0

Hey,

I have this line of code... because I dont want to allow things like & or ! or * etc... but I DO want to allow _ and -

$url = ereg_replace("[^A-Za-z0-9 ]", "", $url);

Can anyone help me?

Dan

3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by JobBrown
0

ereg_replace was deprecated in PHP 5.3 so usage of it is not recommended.

You can however use a similar function preg_replace

$url = preg_replace("[^A-Za-z0-9_- ]", "", $url);

This will allow any letters or numbers, underscores, hyphens or spaces.

Hope this helps.

0

Dan,
what exactly are you trying to do?...
you could try

$url = "http://someurl.com/some****&!!!!!other_text";
$url = str_replace("*", "", $url);
$url = str_replace("&", "", $url);
$url = str_replace("!", "", $url);
// or str_replace("whatever you want removed","replacement value",string_to_search);
echo "url = " . $url . "<br>";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.