&#982 strip these?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
jasondavis
Forum Commoner
Posts: 60
Joined: Sat Feb 04, 2006 5:35 pm

&#982 strip these?

Post by jasondavis »

How can I strip things like &#982 out of a variable, Im not sure what they are called but hteres like 100's of them
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Those are HTML entities (or sometimes refered to as ASCII characters, though I was told that was not the correct name for them). Do you want to get rid of them altogether? If so, use

Code: Select all

str_replace()
.
jasondavis
Forum Commoner
Posts: 60
Joined: Sat Feb 04, 2006 5:35 pm

Post by jasondavis »

using that how could i remove "&"
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have you read the manual page I refered you to? It gives examples. Try one. If it doesn't work, post back.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

$string = preg_replace('/&#\d+;/', '', $string);
Using str_replace() could be better though. Just str_replace all & to &
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

str_ functions are faster than preg_ functions. But if this is not a high volume app, or you need the flexibility of regular expression matching, use the preg_ functions.
Post Reply