Forum Moderators: coopster

Message Too Old, No Replies

Extracting Info Using eregi()

can I do this?

         

dreamcatcher

7:28 pm on Feb 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a chinese actors/actresses database on my website which I`m currently updating. Each page title has the title in the format:


Actor @ M-Dream (Chinese Name)

Is it possible to extract the information that is between the () brackets? In this case: Chinese Name

This is the code I have so far:


$url = "http://www.mysite.com/actor.php";

$filehandle = @fopen($url, 'r');
$filesize = 25000;
$stuff = fread($filehandle, $filesize);
fclose($filehandle);

if (eregi("<title>(.*)</title>", $stuff, $out))

{

$title=$out;

}

foreach($title as $display)

{

echo $display;

}

This is succesfully displaying the whole title. I`m a little unsure of the code to extract the info between the brackets. I`m assuming this is possible?

Thanks.

IanKelley

12:16 am on Mar 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use perl compatible regular expressions instead, ereg is slower and less powerful, no reason to use it.

Check the PHP manual for preg_match_all()

brotherhood of LAN

12:20 am on Mar 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This will match one instance of the brackets, as Ian said, preg_match_all would do the job if you have more than one set of brackets to match.

preg_match("'\(([^\)]*)'",$input,$matches);

The contents of the brackets would be in $matches[1]

dreamcatcher

7:17 am on Mar 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK guys, thanks for the help and advice. :)