I have this text string:
$text="::tower_unit::7::/tower_unit::<br/>::tower_unit::8::/tower_unit::<br/>::tower_unit::9::/tower_unit::";
Now I want to get the value of 7,8, and 9
how to do that in preg_match_all ?
I’ve tried this:
$pattern="/::tower_unit::(.*)::\/tower_unit::/i";
preg_match($pattern,$text,$matches);
print_r($matches);
but it still all wrong…
You forgot to escape the slash in your pattern. Since your pattern includes slashes, it’s easier to use a different regex delimiter, as suggested in the comments:
I also converted
(.*)to(\d+), which is better if the token you’re looking for will always be a number. Plus, you might want to lose theimodifier if the text is always lower cased.