user3437098 user3437098 - 5 months ago 30
PHP Question

Replace string between two brackets and get a variable on the repleaced string

This is my input string: (Picture will variate)


This is what i want to output:

<img src="">

How can i use preg_replace or other alternatives to do this?


Just for sake of completeness, here's the preg_replace solution...

$patterns = array("/\[image\]/", "/\[\/image\]/");
$replacements = array("<img src=\"", "\">");

$string = "[image][/image]";

echo preg_replace($patterns, $replacements, $string);

Live Demo