使用php替换文本

使用php替换文本,php,str-replace,php-5.3,php-5.4,Php,Str Replace,Php 5.3,Php 5.4,我有一个问题,我想用php用str_replace替换一个文本。我在tinymce编辑器中有一个文本区域,我在那里加载了图像。图像保存在数据库../image.png中。现在我想用storage.com替换../ $text = $this->input->post('text', TRUE); $text = addslashes($text); $text = str_replace('../','http://storage.co

我有一个问题,我想用php用str_replace替换一个文本。我在tinymce编辑器中有一个文本区域,我在那里加载了图像。图像保存在数据库../image.png中。现在我想用storage.com替换../

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

请帮帮我。

您的替换代码似乎工作正常。代码的第一行可能会返回超出预期的内容

$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

替换之前,
$text
的值是多少。您想在数据库中替换它还是只在php中替换?在插入数据库之前,我想用Jenz替换$text我得到了:text text/