PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
php3ch0
Forum Contributor
Posts: 212 Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK
Post
by php3ch0 » Fri Apr 28, 2006 2:09 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Apr 28, 2006 4:01 pm
it has a pretty regular pattern...
php3ch0
Forum Contributor
Posts: 212 Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK
Post
by php3ch0 » Sat Apr 29, 2006 3:33 am
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
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Sat Apr 29, 2006 5:02 am
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/
php3ch0
Forum Contributor
Posts: 212 Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK
Post
by php3ch0 » Sun Apr 30, 2006 4:07 am
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);
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Mon May 01, 2006 11:49 am
with the current regex it will replace the exact thing you're trying to catch... use
preg_match() instead