Welcome to WebmasterWorld Guest from 107.20.34.173

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

ereg replace()

DEPRECATED need alternate function

     

whatson

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

WebmasterWorld Senior Member 10+ Year Member



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 .

g1smd

6:24 pm on Jun 2, 2012 (gmt 0)

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



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


The
'/  /'
part is VERY important.

whatson

12:50 am on Jun 3, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

incrediBILL

4:05 am on Jun 3, 2012 (gmt 0)

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



Showing us your code would be helpful, especially line 4

SteveWh

6:31 am on Jun 3, 2012 (gmt 0)

5+ Year Member



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

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

whatson

12:54 pm on Jun 3, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Steve that worked great.

g1smd

4:15 pm on Jun 3, 2012 (gmt 0)

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



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

Featured Threads

Hot Threads This Week

Hot Threads This Month