Re: Regular Expression ? from newbie
| From: | _lallous | Date: | Wed, 12 Sep 2001 09:37:10 +0000 |
| Subject: | Re: Regular Expression ? from newbie | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-67019@lists.php.net to get a copy of this message | ||
here's your PHP code,
<?
$mem = '
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td align=center>banana</td>
<td align=left>.46</td>
<td align=right>.55</td>
</tr>
<tr>
<td align=center>pear</td>
<td align=left>.38</td>
<td align=right>.51</td>
</tr>
<tr>
<td align=center>apple</td>
<td align=left>.59</td>
<td align=right>.33</td>
</tr>
</table>';
$re2 =
"/.*?<tr[^>]*>.*?<td[^>]*>(.+?)<\/td>.*?<td[^>]*>(.+?)<\/td>.*?<td[^>]*>(.+?
)<\/td>.*?<\/tr>/is";
$re1 = '/<table cellspacing="2" cellpadding="2"
border="1">(.+?)<\/table>/is';
if (preg_match($re1, $mem, $matches))
{
if (preg_match_all($re2, $matches[1], $tddata, PREG_SET_ORDER))
{
for ($i=0;$i<count($tddata[0])-1;$i++)
{
echo "name={$tddata[$i][1]} p1={$tddata[$i][2]}
p3={$tddata[$i][3]}\n";
}
}
}
?>
"Craig Westerman" <westerman@chanuteks.com> wrote in message
news:HGENKAHJCCKOGANPDCBIMEDKCOAA.westerman@chanuteks.com...
> Consider the following table that I grabbed from another web site using:
>
> <?
> $url = 'http://www.abc123xyz.com';
> $lines_array = file($url);
> $lines_string = implode('', $lines_array);
> ?>
>
> =======================================
>
> <table cellspacing="2" cellpadding="2" border="0">
> <tr>
> <td align=center>banana</td>
> <td align=left>.46</td>
> <td align=right>.55</td>
> </tr>
>
> <tr>
> <td align=center>pear</td>
> <td align=left>.38</td>
> <td align=right>.51</td>
> </tr>
>
> <tr>
> <td align=center>apple</td>
> <td align=left>.59</td>
> <td align=right>.33</td>
> </tr>
> </table>
>
> =======================================
>
> The fruit lables don't change, but prices change daily.
> How would I parse JUST the two prices to the right of the word pear into a
> new html table?
>
> How would I parse the word pear AND the two prices to the right into a new
> html table?
>
> I think the answers will help me understand better.
>
> Thanks
>
> Craig ><>
> westerman@chanuteks.com
>