Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie question: search within an external html 1

Status
Not open for further replies.

123456programmer

Programmer
Joined
Aug 3, 2003
Messages
105
Location
AU
Hey i m a newbie, and i am trying to run a php script with my macromedia flash program.
what i want the php to do is to look up for a word in an html file.
the word is: Gateway
in the html code it is writeen like this:
Gateway ***.***.**.**
the part with * the IP of the client. so it change quite often.
In the source of the html code it is written like this:
<TD ALIGN=RIGHT><B>Gateway</B></TD>
<TD>210.9.141.233</TD>
so i wanted the php to look up for the word Gateway, and execute the line.
thanks in advance
 
then u must know how to strip off HTML tags. try regular expressions...

a simple one being:
$str=&quot;<td><b>asdasd</b></td>&quot;;
$str=preg_replace(&quot;/<[^>]*>.*</[^>]>/U&quot;,&quot;&quot;,$str);
echo $str;

Known is handfull, Unknown is worldfull
 
Thanks for your replies :)
But i still can't make it.
what i did, is:

<?php
$url = &quot;$sourcepage = &quot;$url/status.htm&quot;;
$handle = fopen(&quot;$sourcepage&quot;, 'r');
$str=preg_replace(&quot;/<[^>]*>.*</[^>]>/U&quot;,&quot;&quot;, $handle);
echo $str;
?>

i also tried the fseek() but i had some error :(
thanks in advance
 
Your code may have multiple problems.

First, I'd recommend that you strip all inputs from the returns at the ends of lines.

Second, I don't understand what you're trying to match with that regular expression.


Given the following HTML output:
Code:
<html><body><table><tr>
<TD ALIGN=RIGHT><B>Gateway</B></TD>
<TD>210.9.141.233</TD>
</tr></table></body></html>

The following script:
Code:
<?PHP
$fd=fopen(&quot;[URL unfurl="true"]http://server/file.htm&quot;,&quot;r&quot;);[/URL]
while ($line=fgets($fd,6000))
{
	$alltext .= rtrim($line);
}
fclose ($fd);

preg_match ('/(Gateway)<\/B><\/TD><TD>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/i', $alltext, $results);

print_r($results);
?>

Seems to match what you're looking for. It's output is:
Code:
Array
(
    [0] => Gateway</B></TD><TD>210.9.141.233
    [1] => Gateway
    [2] => 210.9.141.233
)


Want the best answers? Ask the best questions: TANSTAAFL!!
 
hi, i seem to have made a mistake:
now does it work?
$str=preg_replace(&quot;/<[^>]*>.*</[^>]*>/U&quot;,&quot;&quot;, $handle);


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top