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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ereg()

Status
Not open for further replies.

novice2004

Programmer
Joined
Feb 2, 2004
Messages
62
Location
US
Help please,
How to go about it?
From my web site I would like to automaticaly
read other web site lets say find "USD" and its equivalent value (which in our case is 10,506),
then place it on my web site.
I think I need to use
some expression in function eregi()


<TD align=left><B>Swiss</B></TD>
<TD align=middle>CHF</TD>
<TD align=right>1</TD>
<TD align=right>15,988</TD></TR>


<TR align=middle bgColor=#f4f4f4>
<TD align=left><B>USA</B></TD>
<TD align=middle>USD</TD>
<TD align=right>1</TD>
<TD align=right>10,506</TD></TR>
<TR align=middle bgColor=#f4f4f4>


so far I have:

$file = fopen(" "r");


while (!feof($file))
{
$line = fgets($file);
if (eregi(">USD<", $line, $result)) ????????????????????
{}

}

Thank you
 
First, I wouldn't use any of the regular expression operators. You're not looking for a string that fits a pattern, you're looking for a string that matches another string. There's no need to incur the memory and processor overhead necessary to use the regular expression functions.

With the input you've given, I would inside the if-block: read the next line and discard it; read another line; use one of the regular expression functions to get out the value.

Code:
<?php
$file = fopen("test_data.txt", "r"); 

while ($line = fgets($file)) 
{
	if (strstr($line, '>USD<') !== FALSE)
	{
		$line = fgets($file);
		$line = fgets($file);
		
		$foo = preg_replace('/.*>([\d,]+)<.*/', '$1', $line);
		
		print_r ($foo);
	}
}
?>

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top