How to convert a string for url? or How to remove space or any special chrecter from my string?

How to convert a string for url?
How to remove space or any special chrecter from my string?
or How to convert a string in without space and without special character.

use this code and you will got  a string for url or add with + sign


<?php

function filter_text($name){

$name = htmlentities(stripslashes($name), ENT_QUOTES);
$name = preg_replace('/[^a-z A-Z 0-9]/','+',$name);
$filtered = str_replace(' ', '+', strtolower($name));
return $filtered;

}
?>


if you got twoo or three + in a string so u can use two times these lines
$filtered1 = str_replace('++', '+',$filtered);
$filtered2 = str_replace('++', '+',$filtered1);



like

<?php
function filter_text($name){
$name = htmlentities(stripslashes($name), ENT_QUOTES);
$name = preg_replace('/[^a-z A-Z 0-9]/','+',$name);
$filtered = str_replace(' ', '+', strtolower($name));
$filtered1 = str_replace('++', '+',$filtered);
$filtered2 = str_replace('++', '+',$filtered1);
return $filtered2;
}
?>

Comments