tags:

views:

60

answers:

2

Hi: I client of mine, have 542 php files (yes a lot) each one of them call a iframe with certain parameters every one different. So i wanna make this a little more efficent, and convert all files to a database, but for this i need to obtain 2 things

  1. The contain of the title tag
  2. One parameter of the iframe (cat)

I show the iframe example

<iframe src="http://www.todobariloche.com/shop/xml_galeria1.php?cat=1044&amp;amp;cant=21&amp;amp;ord=MAS_OFERTADOS&amp;amp;pais=MLA" name="nombre_frame" width="500" height="1000" id="nombre_frame" border="0"> </iframe>

I hope somebody could help me i just need the preg match in PHP.

Thanks in advance.

+4  A: 

If that's a one-off job, then you can probably just hack it with grep and regular expressions.

If you want to do it properly, then you'll need DOM and XPath.

$doc = DOMDocument::loadHTML($page);
$xp = new DOMXPath($doc);
$src = $xp->evaluate('string(//iframe/@src)');
$title = $xp->evaluate('string(//title)');
porneL
Beats the hell out of regular expressions.
GZipp
Hi: Thanks, Its (i hope) one-off job, but i wanna do it right :DI gonna try it and then i came back here, to tell you my results
bicho44
+1  A: 

Something like this should do the job:

if (preg_match("/http:\/\/www\.todobariloche\.com\/shop\/xml_galeria1\.php\?cat=(.*?)&amp;cant=(.*?)&amp;ord=(.*?)&amp;pais=([^\"]*)/i", $pageData, $parameters)) {
    // $parameters[1] and on now contains the matched patterns.
}

.*? indicates that the pattern catching should be ungreedy. ([^\"]*) is just a way to prevent it from capturing anything after the end of the src attribute.

/<title>(.*?)</title>/i should work for the title unless something strange is going on there.

Emil H
I gonna try this as well :D
bicho44