使用php替换文本

时间:2014-05-22 10:20:00

标签: php str-replace php-5.3 php-5.4

我有一个问题,我想用php替换一个带有str_replace的文本。我在tinymce编辑器中有一个textarea文本,我在那里加载图像。图像保存在数据库../image.png现在我想要用storage.com替换../但不要替换,我不明白问题在哪里

$text         = $this->input->post('text', TRUE);
$text         = addslashes($text);
$text         = str_replace('../','http://storage.com/',$text);

请帮帮我。

1 个答案:

答案 0 :(得分:0)

您的替换代码似乎工作正常。您的代码的第一行可能会返回除您期望的其他内容

$text         = '../image.png';
echo $text . "\n";
$text         = addslashes($text);
$text         = str_replace('../','http://storage.com/',$text);
echo $text . "\n";

此代码输出

../image.png
http://storage.com/image.png