-
Help with search
I was wondering if there was an easy way to do this. I need to search a image tags in a bb post. The tags can be [ img] or < img> (since I dont want vB to try and do something with it I put a space).
Right now I have a loop to find the [ img] start and ending tags. It works great using strpos. But I really dont want to have to do this long loop again to find the start and end < img> tags. So I was wondering if anyone had any idea on how I can do this in one loop. Like with something simular to preg_match or something.
-
Re: Help with search
well, what do you want to do with these tags when you found them?
if want to replace them with something else, you can use preg_replace or (if its a more complex replacement) preg_replace_callback.
(or the other regexp functions, if don't like the preg_* syntax)
Code:
$string = "Hello [ img]you.jpg[/ img] !";
echo preg_replace( '@\[ img\](.*)\[/ img\]@', '<img src="$1"/>', $string );
this echoes Hello <img src="you.jpg"> !