Php 替换不起作用?
Php replace not functioning?
im return 这个 url 到数组
$imagelink = $_SERVER['SERVER_NAME'] ."/test/wp-content/plugins/test/captcha/" .$captchaURL.".jpeg";
当我在我的数组之一中 return $imagelink;
时,它显示:
"Image URL":"localhost/test/wp-content/plugins/test/captcha/LTgLUodmPu.jpeg"
我尝试替换 /
$imagelink = $_SERVER['SERVER_NAME'] ."/test/wp-content/plugins/test/captcha/" .$captchaURL.".jpeg";
$replace = str_replace('\/','/',$imagelink);
return $replace;
结果还是一样?它似乎没有取代。为什么?
它与我也使用 preg_replace() 函数相同。
有答案请帮忙
您正在尝试用正斜杠替换正斜杠。
尝试以下任一方法:
$imagelink = str_replace('\', '/', $imagelink); // Replace backslash with forward
$imagelink = str_replace('/', '\', $imagelink); // Replace forwardslash with backslash
在转义字符串
时使用双引号 "
$replace = str_replace("\/","\",$imagelink);
使用以下代码:
<?php
$imagelink = $_SERVER['SERVER_NAME'] ."/test/wp-content/plugins/test/captcha/" .$captchaURL.".jpeg";
$replace = str_replace('/','\',$imagelink);
return $replace;
im return 这个 url 到数组
$imagelink = $_SERVER['SERVER_NAME'] ."/test/wp-content/plugins/test/captcha/" .$captchaURL.".jpeg";
当我在我的数组之一中 return $imagelink;
时,它显示:
"Image URL":"localhost/test/wp-content/plugins/test/captcha/LTgLUodmPu.jpeg"
我尝试替换 /
$imagelink = $_SERVER['SERVER_NAME'] ."/test/wp-content/plugins/test/captcha/" .$captchaURL.".jpeg";
$replace = str_replace('\/','/',$imagelink);
return $replace;
结果还是一样?它似乎没有取代。为什么? 它与我也使用 preg_replace() 函数相同。
有答案请帮忙
您正在尝试用正斜杠替换正斜杠。 尝试以下任一方法:
$imagelink = str_replace('\', '/', $imagelink); // Replace backslash with forward
$imagelink = str_replace('/', '\', $imagelink); // Replace forwardslash with backslash
在转义字符串
时使用双引号 "$replace = str_replace("\/","\",$imagelink);
使用以下代码:
<?php
$imagelink = $_SERVER['SERVER_NAME'] ."/test/wp-content/plugins/test/captcha/" .$captchaURL.".jpeg";
$replace = str_replace('/','\',$imagelink);
return $replace;