• 0

[PHP] remove unwanted characters from a string


Question

2 answers to this question

Recommended Posts

  • 0

don't know much PHP, but use regular expressions

ereg_replace

http://us4.php.net/regex

for your example it would be something like

ereg_replace("[^A-Za-z0-9-_.]", "", $string);

replace everything not mathced by regexp with blank

(you may have to handle the . by escaping it ?????)

  • 0
  spydoor said:
don't know much PHP, but use regular expressions

ereg_replace

http://us4.php.net/regex

for your example it would be something like

ereg_replace("[^A-Za-z0-9-_.]", "", $string);

replace everything not mathced by regexp with blank

(you may have to handle the  .  by escaping it ?????)

585533353[/snapback]

thanks!

I ended up using ereg_replace("[^[:alnum:]+.+_+-]", "_", $string);

:D

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.