Welcome to WebmasterWorld Guest from 54.196.244.186

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

ereg replace()

DEPRECATED need alternate function

     
3:58 pm on Jun 2, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 21, 2002
posts: 1541
votes: 0


Looking for an alternate function to:

ereg_replace("[^A-Za-Z0-9.]","", $string)

i.e. something that will remove all characters from a string other than a-z, 0-9 and .
6:24 pm on June 2, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Try:
preg_replace('/[^A-Za-Z0-9.]/','', $string)


The
'/  /'
part is VERY important.
12:50 am on June 3, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 21, 2002
posts: 1541
votes: 0


I got this response
Warning: preg_replace() [function.preg-replace]: Compilation failed: range out of order in character class at offset 7 in C:\xampp\htdocs\test.php on line 4
4:05 am on June 3, 2012 (gmt 0)

Administrator from US 

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 25, 2005
posts:14624
votes: 88


Showing us your code would be helpful, especially line 4
6:31 am on June 3, 2012 (gmt 0)

Preferred Member

5+ Year Member

joined:July 25, 2006
posts: 460
votes: 0


The second z needs to be lowercase, that's all:

preg_replace('/[^A-Za-z0-9.]/','', $string)
12:54 pm on June 3, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 21, 2002
posts: 1541
votes: 0


Thanks Steve that worked great.
4:15 pm on June 3, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Ah. Didn't spot the typo in the OP. :)