I don't want to muddle up this question with the gory details of what I'm trying to do so I'll just simplify it as much as I can.
I wish to replace every instance of X between every opening and closing tag Y (<Y></Y>). X is defined by a list of words in an array that i created and each one between those tags must be parsed out. However, nothing outside of those tags should be parsed. Here is what I thought would work:
X_array = array("item1","item2","item3","item4");
$string = "Today item1 will be shot into a vat of <Y>acetone and boiled until item4 and item1</Y> confess to their crimes against Open Source Programming.";
$X_List = implode("|",$X_array);
$string = preg_replace( "#<y>((.)?\b($X_List)\b)(.*)?</y>#si", "<y>\2<a target=\"_blank\" href=http://www.php.net/\3>\3</a>\4</y>", $string);
However, the above doesn't work for me. It only seems to parse out one per tag. I'm admittedly, a regexp noob. Can anyone help?