Re: Help with preg_match_all()

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

 



Curt Zirzow wrote:
And so on.. It's a kind of a template system... well... I need to
create a expression to get all the tags from the HTML with
preg_match_all() in order to have them in a array...
So your looking from something that starts with '{' and continues
while not a ')' ...

/{([^}]*?)}/

If you are already using the "?" meta character then you can simply do this:

/{(.*?)}/

The "while not"-approch is useful if you don't want to use the "?" meta character (to be compatible to regex engines which don't support this). But then it would look like this:

/{([^}]*)}/


But all these expressions are to lazy for the required work. The tags should be matched more exactly using this:


/{$([\w\.]+)}/

This implies that the variable names always begin with a dollar character and they can contain upper and lowercase characters, numbers, underscores and periods. The variable name must contain at least one character, so {$} is not matched.

--
Bye, K <http://www.ailis.de/~k/> (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger k@xxxxxxxx to get public key)

Attachment: signature.asc
Description: OpenPGP digital signature


[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