Re: Regex Parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



rsw@xxxxxxxxxxx wrote:

preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $content,

$matches);


You make it look so easy, thanks! That takes care of step one, but how do I make it so everything in $content where there is a level set, is replaced with ###LEVEL?###

Does #Uim tell it to only get the first [/LEVEL1] rather than going to the
bottom and getting the second?  I've always wondered how to tell it to get
the first, rather than the last...

Thanks in advance!
U means it'll become UNgreedy (means it ends at the first occurence instead of the last),
m means multiline, so . also matches \n and \r chars.
i means it's case-INsensitive. Which I thought was just useful ;)


print_r($matches) will show what comes out exactly how. Then at some point you'll probably be able to echo something like echo '###LEVEL'.$matches[1][$i].'###';
where $i would be the part you're echoing from.


Anyway, it'll be SOMETHING like that. I tend to always print_r the results first, and then write more code based on the result.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux