Forum Moderators: coopster

Message Too Old, No Replies

Problem with ereg statement

         

catch2948

11:06 am on Feb 10, 2004 (gmt 0)

10+ Year Member



I have a problem with an ereg statement that I use to parse a certain datafeed with. Please see below:

datafeed:

"This is the website title", "This is the website URL", "This is the website tracking URL", "This is the website description", "This is the website counter") ,

ereg statement:

ereg("^\"([^\"]+)\", \"[^\"]+\", \"([^\"]+)\", \"([^\"]+)\", \"([^\"]+)\")", $datafeed[$i], $matches);

Given the examples above, the ereg statement returns the following:

$matches[1] = This is the website title
$matches[2] = This is the website tracking URL
$matches[3] = This is the website description
$matches[4] = This is the website counter

Why is my ereg statement not returning 'This is the website URL' for any of the matches?

As always, thank you in advance for your replies :-)

catch2948

11:12 am on Feb 10, 2004 (gmt 0)

10+ Year Member



Please disregard the ) at the end of the datafeed (just a typo) :-)

coopster

4:07 pm on Feb 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Before we tear into the regex, have you considered using explode() [php.net] for this?

catch2948

7:59 pm on Feb 10, 2004 (gmt 0)

10+ Year Member



No, I hadn't thought about it ... Although I do use explode in another section of the script

coopster

3:47 am on Feb 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Come to think of it, where is your datafeed coming from? By the sounds of your variable name it is a file. If that is true, you should consider using fgetcsv() [php.net]. If not, did explode work for you?