[thelist] PHP regex script returns empty array

Jack Timmons jorachim at gmail.com
Sat Apr 11 07:25:26 CDT 2009


On Sat, Apr 11, 2009 at 4:52 AM, Madhu Menon <chef at shiokfood.com> wrote:

> preg_match_all ($pattern, $rawtext, $results);
>
> So in theory, this should display all the matches found in the text, right?
>

In theory, not at all.
A very quick search for the preg_match_all function on PHP.net turns up the
answer in the documentation [1].

In short, preg_match_all returns a multi-dimensional array. You either play
with the default, or tell PHP how you want that array formatted.

So, $results[0] is an array containing the text that matches the pattern you
provided. From then on, $results[n] (n>0) will match for each capture you
provide.


[1] - http://us.php.net/preg_match_all

-- 
-Jack Timmons
http://www.trotlc.com
Twitter: @codeacula



More information about the thelist mailing list