You need to enclose the expression in parenthesis for the back reference to work. Since you need to replace based on your php array, you also need to use the 'e' switch at the end of the regex:
<?php
$str="String of text containing item1 and item2";
$x['item1']="Item 1";
$x['item2']="Item 2";
$str=preg_replace('/(item\d+)/e','$x[$1]',$str);
print $str;
?>
hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244