【问题标题】:Php replace not functioning?php替换不起作用?
【发布时间】:2015-08-26 10:02:08
【问题描述】:

我将此网址返回到数组中

$imagelink = $_SERVER['SERVER_NAME'] ."/test/wp-content/plugins/test/captcha/" .$captchaURL.".jpeg";

当我 return $imagelink; 在我的一个数组中时,它会显示:

“图片网址”:“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() 函数相同。

如果你有答案,请帮忙。

【问题讨论】:

  • 用你要替换的东西?
  • /替换/???

标签: php url preg-replace str-replace


【解决方案1】:

转义字符串时使用双引号"

$replace = str_replace("\/","\\",$imagelink);

【讨论】:

  • 我已经更新了代码。 $replace = str_replace("\/","\\",$imagelink);
【解决方案2】:

您正在尝试用正斜杠替换正斜杠。 尝试以下任何一种:

$imagelink = str_replace('\\', '/', $imagelink); // Replace backslash with forward
$imagelink = str_replace('/', '\\', $imagelink); // Replace forwardslash with backslash

【讨论】:

    【解决方案3】:

    使用以下代码:

    <?php 
    $imagelink = $_SERVER['SERVER_NAME'] ."/test/wp-content/plugins/test/captcha/" .$captchaURL.".jpeg";
    $replace = str_replace('/','\\',$imagelink);
    return $replace;
    

    【讨论】:

      猜你喜欢
      • 2015-06-10
      • 2016-02-15
      • 2016-10-05
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 2018-05-02
      • 2018-04-27
      • 2018-03-15
      相关资源
      最近更新 更多