Forum Moderators: coopster
I'm writing a script that will look at a string comprising of a page's source code to extract nine variables contained inside.
Right now I'm faced with the problem of trying to isolate the variables.
Let's say part of the source code looks like this:
...
<td class="class" width="175" height="20" align="right" valign="top">Class: Calculus</td>
<td>***</td>
<td class="class" width="175" height="20" align="right" valign="top">Grade: A</td>
<td>***</td>
<td class="class" width="175" height="20" align="right" valign="top">Year: 1988</td>
<td>***</td>
...
What would be the best approach to isolate the values "Calculus", "A" and "1988"?
I've been playing around with explode, but I don't think that's giving me the solution I need.
Thanks.
Looks like you are going to need regular expressions [us2.php.net] for this ;)
Try something like the following:
$pattern = "/<td[^>]+>([^<\/td>]+)<\/td>/i";
$matches = array();
if([url=http://us2.php.net/preg-match-all]preg_match_all[/url]($pattern,$string,$matches)) {
echo '<pre>';
[url=http://us2.php.net/manual/en/function.print-r.php]print_r[/url]($matches);
echo '</pre>';
}
Where
$string is the HTML code you referenced above. Good luck! :)