[TYPO3] preg_match_all problem.
Peter Klein
peter at umloud.dk
Sun Sep 30 11:25:43 CEST 2007
"Pete Novak" <pete.n at hotmail.com> wrote in message
news:mailman.1.1191067195.28204.typo3-english at lists.netfielders.de...
> Hi all,
>
> I have the following
>
> $content = ' lkdjsh flsd+++AAA+++hflk jshdflkh gskldjfh gkljsdhf k
> ghsdkflh gsjkldhf glskd+++DRASVD+++uhfg lushdliufgh sdiufh
> gs+++HGFGS+++ldiuhf gklsdjhflkgj sdhfh gsdjkfhg skljdfh gjk';
>
> when I use preg_match ('/+++[A-Z]+++/', $content);
>
> It doesent work, why?
>
Hi Pete.
1) Your regexpression is wrong.
a) The "+" char is a regex qualifierer, and should be escaped if used as
a litteral character.
b) You are only testing if there's ONE letter between A-Z, not more.
2) If you want to test the entire $content, and get the matches returned as
a array, you should use preg_match_all
Try this:
preg_match_all('/\\+\\+\\+[A-Z]+\\+\\+\\+/', $content,$matches);
$matches then contains an array of the matches found in $content.
BTW: If you are having trouble with Regular Expressions, try RegexBuddy
http://www.regexbuddy.com/
It allows you to create and test complex regexpresions, and alos contains a
library of the more common expressions, like validating email addreses etc.
--
Peter Klein / Umloud Untd.
More information about the TYPO3-english
mailing list