homepage Welcome to WebmasterWorld Guest from 54.226.191.80
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
ereg replace()
DEPRECATED need alternate function
whatson




msg:4460765
 3:58 pm on Jun 2, 2012 (gmt 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 .

 

g1smd




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

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

The
'/ /' part is VERY important.
whatson




msg:4460845
 12:50 am on Jun 3, 2012 (gmt 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

incrediBILL




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

Showing us your code would be helpful, especially line 4

SteveWh




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

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

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

whatson




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

Thanks Steve that worked great.

g1smd




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved