how to replace a single slash with a double slash? I have this text:
"/data/folder/" and i need get "//data//folder//"
I am trying to replace, but getting an error:
$data = str_replace("\", "\\", $data);
You want to replace the slash, but yours str_replacehas a backslash.
str_replace
Try:
$data = str_replace("/", "//", $data);
The reason for the error:
\shielding is used. Thus, \in "\"fact eludes the second ".
\
"\"
"
Are you talking about backslashes or normal backslashes? anyway check the code below for both of them:
$str = '\dada\dsadsa'; var_dump(str_replace('\\', '\\\\', $str)); $str = '/dada/dadda'; var_dump(str_replace('/', '//', $str));
, , escape- , ". :
str_replace("\\", "\\\\", $data);
from what you say, you most likely want to use slashes rather than backslashes, as shown in @codaddict figure.
You can use the following code:
<?php $str = addcslashes("Hello World!","W");?> <?php echo $str;?> <br/> <?php $str2 = addcslashes($str,"W"); echo $str2; ?>