Hi. Recently, I'm playing with something related to BBCode in phpBB3. When I trace my database, the posts table and for a random post. I found that the image tag is written this way. There are 8 random characters generated between [img: ... ] for each post. My question is, how can I make use of preg_replace() to replace the random characters into this way..
instead of str_replace use this $your_bb_string = "[img:fcjsgy5j]"; print_r(sscanf($your_bb_string, "[img:%s]"));
You don't get me.. I want to convert [img:fcjsgy5j]http://imageurl.jpg[/img] to <img src="http://imageurl.jpg"> and fcjsgy5j is just a garbage value. Thanks.
<?php function bb_img_to_html_img($string){ $pattern = '#\[img\:.+\](.+)\[\/img\]#iUs'; $replace = '<img src="$1" />'; return preg_replace($pattern, $replace, $string); } print("\n\nTag test [img:sldkjsd]:\n"); $string = "[img:sldkjsd]http://www.somesite.com/image.jpg[/img]"; print(bb_img_to_html_img($string)); ?> PHP: This matches the [img:sometext] pattern only - it won't replace img tags where the garbage text doesn't exist.