hi
i want to replace all characters in a string which are not letters,numbers or a dot with a underscore
for example
http://www.mydomain.com/index.php?st=1
would be converted to
http_www.mydomain.com_index.php_st_1
replace in string
Moderator: General Moderators
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Belongs in the regex forum...but:
Code: Select all
<?php
$string = 'http://www.mydomain.com/index.php?st=1';
echo preg_replace('/[^[:alnum:].]/', '_', $string); //http___www.mydomain.com_index.php_st_1
?>