简体   繁体   中英

Replace a text using php

I have a problem,I want to replace a text with str_replace using php.I have a textarea in tinymce editor with text and I loaded image there.The image is saved in database ../image.png now I want to replace ../ with storage.com but don't replace and I don't understand where is the problem

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

Help me please.

Your replacement code seems to work fine. The first line of your code probably returns something else than what you expect

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

This code outputs

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM