0

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

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

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 <> tags?

Thanks

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.