3
I am trying to remove the backslashes to open the image URL, I found a way to replace, but part of my string was lost:
function formatURL( $url )
{
echo $url."<br />";
$url = str_replace('\\', '/', $url);
echo $url."<br />";
}
echo "http://10.0.0.1/fotoou/aplic\1\7\1\3\9\8\1\\1893171_1.jpg<br />";
$url = formatURL("http://10.0.0.1/fotoou/aplic\1\7\1\3\9\8\1\\1893171_1.jpg");
echo $url;
The strange thing is that my return is:
http://10.0.0.1/fotoou/aplic\9\8\1893171_1.jpg
http://10.0.0.1/fotoou/aplic\9\8\1893171_1.jpg
http://10.0.0.1/fotoou/aplic/9/8/1893171_1.jpg
Part of the lost string:
\1\7\1\3\
Opa valeu Wallace! And in case my string is coming from a variable? How can I guarantee the integrity of the string?
– Alessandro Gomes
The operation is the same @Alessandrogomes.
$teste = "http://teste\\path\\to\\action"
– Wallace Maxters
in my case is the following :
$url = $registro["FOTO1"];
and the string already comes with only one bar– Alessandro Gomes
No, it doesn’t come with "one bar". That "one bar" I said is in statement of the string (where you really need to escape, on account of the PHP interpreter). If it comes from elsewhere (as in
$_POST
or the database), just pass the parameter in its function, because thePHP
will process it.– Wallace Maxters