mjpr
1
Hi,
I have a form with a textarea that gets filled with content like:
[CONTENT id=77165][CONTENT id=77164][CONTENT id=77162][CONTENT id=77159][CONTENT id=77158]
I need to extract only the integer id’s.
I have so far:
$input = "[CONTENT id=77165][CONTENT id=77164][CONTENT id=77162][CONTENT id=77159][CONTENT id=77158]";
$regex = '#\\[CONTENT id="(.*?)"\\]#s';
preg_match_all($regex, $input, $matches, PREG_SET_ORDER);
print '<pre>';
print_r($matches);
print '</pre>';
I get an empty array.
I’d like to achive an array with each id as an array element.
How can I do that?
Thanks
regex is looking for
[CONTENT id=“77165”]
but you have
[CONTENT id=77165]
mjpr
3
Nice.
It was my bad. I removed the " from the input string and didn’t change the regexp.
But I still can’t get each id only as array elements. 
In addition to what crmalibu pointed out, if you know you only want to capture digits, IMHO you should use (\d)+ instead of the everything atom
mjpr
5
Thanks for the help.
I now have:
$regex = '/(\\d+)/';
preg_match_all($regex, $input, $matches, PREG_PATTERN_ORDER);
print_r($matches);
And I get what I needed. 