Jump to content

preg_replace problem.


Cyberek

Recommended Posts

Hello.

Im working on a function:

function image_vote_img_replace($content) {
preg_match_all('/<img[^>]+>/i',$content, $result, PREG_PATTERN_ORDER);
	foreach ($result[0] as $img_oryg) {
		$result = '<div class="test">'.$img_oryg.'</div>';
		$content = preg_replace( $img_oryg, $result , $content );

	}
return $content;
}

It gets as input content from CMS. It supposed to add overlaping div to each <img src="xxxx" /> so it looks like: <div class="test"><img src="xxxx" /></div>.

But instead i get:

<<div class="test"><img src="xxxx" /></div>>

with additional < and > at beginning and end.

 

I thin ,that it might be first regexp problem, but in second hand - entire img is extracted properly...

 

Thanks in advice.

Martin.

Link to comment
https://forums.phpfreaks.com/topic/230461-preg_replace-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.