From the PHP documentation:
So, $out[0] contains array of strings that Matched full Pattern, and $out[1] contains array of strings Enclosed by tags.
That means in your variable $output_array
the index 0
represents an array of strings containing the values found that close with the full regular expression. Already in the index 1
is another string array containing the values found that close with tags delimited expressions (the parentheses).
For example, see the code below.
preg_match_all("/.*(World).*/", "Hello World", $out);
The result of $out
will be:
Array (
[0] => Array (
[0] => Hello World
)
[1] => Array (
[0] => World
)
)
Finally, what you want is to go through the array that closes with the full expression.
foreach($output_array[0] as $word) {
echo $word;
}
@bfavaretto What’s up? I removed the usefulness and improved the answer a little bit, Sorry the delay. :)
– stderr
Imagine, not even two years :P I had already voted at the time.
– bfavaretto