Page 1 of 1

preg_replace() help

Posted: Fri Apr 28, 2006 2:09 pm
by php3ch0
Hi

I have got some text that has been scraped from an rss feed.

I want to get parts of the data but not others

I have been using preg replace to remove parts that I do not want but I also want to remove a whole chunk of text that is dynamic.

e.g

I want to change
Tonight:
Partly Cloudy.
Low: 4C. Chance of rain: 10%


Tomorrow:
Partly Cloudy.
High: 10C. Low: 5C. Chance of rain: 0%

Current conditions as of 6:50 PM:
Partly Cloudy. Temp: 11C. (feels like 11).
Humidity: 47%

Winds: 16 km/hr.
All times shown are local to Ashford, GBR.
I want to remove the Current conditions

how do I go about this?

Posted: Fri Apr 28, 2006 4:01 pm
by feyd
it has a pretty regular pattern...

Posted: Sat Apr 29, 2006 3:33 am
by php3ch0
if I try something like this

Code: Select all

preg_replace("Current.*GBR","",$text);
I get the following error message:

Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in c:\easyserv\www\al3\index.php on line 222

Posted: Sat Apr 29, 2006 5:02 am
by Chris Corbyn
php3ch0 wrote:if I try something like this

Code: Select all

preg_replace("Current.*GBR","",$text);
I get the following error message:

Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in c:\easyserv\www\al3\index.php on line 222
The Preg functions are PCRE and thus need to have a start and end delimiter that match. Look at the first regex tutorial in the regex forum on these boards ;)

/Current.*?GBR/

Posted: Sun Apr 30, 2006 4:07 am
by php3ch0
OK ive changed the code and the error has gone but it is not filtering what I want it to.

Code: Select all

echo preg_replace("/Current.*?GBR/","",$data);

Posted: Mon May 01, 2006 11:49 am
by n00b Saibot
with the current regex it will replace the exact thing you're trying to catch... use preg_match() instead