PHP - preg_replace with multiple matches

Posted by Neil on Stack Overflow See other posts from Stack Overflow or by Neil
Published on 2009-12-18T04:49:18Z Indexed on 2010/05/04 6:38 UTC
Read the original article Hit count: 248

Filed under:
|
|

Let's say I have a string like:

$text = "<object>item_id1a2b3</object>xxx<object>item_id4c5d6</object>"

I want to convert it to: %ITEM:1a2b3xxx%ITEM:4c5d6

Here's what I've got:

$text = preg_replace("/<object.*item_id([a-zA-Z0-9]+).*<\/object/","%ITEM:$1",$text);

This isn't quite right, as the search is greedy.

Thoughts?

Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about preg-replace