convert backslash to forward slash vice versa
Hi Guys,
this is very easy method to replace the special character with in string .
Example $var = “/var/xyz/html/uploaddata/xyz.html”;
“/”replace with “-”
$str = str_replace(‘/’, ‘-‘, $var);
result is -var-xyz-html-uploaddata-xyz.html
Example $var = “var-xyz-html-uploaddata-xyz.html”;
“-“replace with “/”
$str = str_replace(‘-‘, ‘/’, $var);
result is /var/xyz/html/uploaddata/xyz.html
“/”replace with “\”
Example $var = “/var/xyz/html/uploaddata/xyz.html”;
$test = str_replace(‘/’, “\\”, $var );
result is \var\xyz\html\uploaddata\xyz.html
UPPER to lower latter’s :–
$var = “MY NaMe Is vIkRant sHARma”;
$test= preg_replace(“/[^a-zA-Z]/”, “”, $var );
result is my name is vikrant sharma
Remove unwanted spacial charactor from String :–
$var= “My () Na*9me <<>> is ~# vikra#$n%t #sh@A8rm9a.”;
$test= preg_replace(‘/[^A-Za-z0-9\-\’]/’, ”, $var);
result is my name is vikrant sharma