regex works in PHP fiddle but not in Drupal I am having a problem getting some regex to work in Drupal. The below regex works fine:

&lt;?php
 $test = "1111~~test1&lt;&gt;2222~~test2&lt;&gt;3333~~test3&lt;&gt;44444~~test4&lt;&gt;11112~~test5";
 $regex = '/~~(.*?)(&lt;&gt;|$)/';
 $matches = array();
 preg_match_all($regex,$test,$matches);
 $test = implode(', ', $matches[1]);
 print_r($test);
?&gt;


But when I try to use this to parse the contents of $items[0]["#markup"] in my field file it does not work, even though the content of that field are the same (look at it through print_r). This code works inside the tpl file, but as soon as I replace $test with $items[0]["#markup"] it stops working, does anyone know why this could happen?

EDIT: I think part of the issue is that regex in Drupal may not work with &lt;> tags?

Thanks
Yep, the issue was I couldn't use the &lt;> symbols. Have to use &amp;lt and &amp;gt instead.