» tagged pages
» logout

(Feed found, click Add Page to syndicate.) Error finding feed, please try again » Find feed title

A Blog Page allows you to add entries, for news or other time sensitive postings

(Login required to save to your tagged pages.)
(or Cancel)

Make further edits, (or Cancel)

(Login required to save to your tagged pages.)
(or Cancel)

(Editing anonymously: to be credited for your changes, login or register a new account)

Change Page Permissions? Changing these permissions will adjust who can modify this page.

Anonymous (change)
(change)
(or Cancel)
Upload an image from your computer:
or Copy an image from a URL:
or Erase the current icon:
Icon Preview:

or Cancel

Erase traps? The contents of traps page and all pages directly attached to traps will be erased.

or Cancel

(Editing anonymously: to be credited for your changes, login or register a new account)

other page actions:
traps

traps

Tags Applied to traps

No one has tagged this page.

traps Wiki Pages

Tag Cloud

To further filter what appears in the Things Tagged traps list, select a tag from the Tag Cloud.
What is traps? Edit this page and describe it here.

sorted by: recent | see : popular
Content Tagged traps

Trap Receiver

Trap Receiver is simple enough. What it does, it does well. Its ease is brilliant. Its efficiency is unparalled. Its operation, flawless.

opensource: del.icio.us tag/opensource

PHP Tricks and Traps II: Variable Expansion and Regular Expressions

Thanks to Keith from the UK for pointing out something odd in my book that doesn’t seem to work as it did in earlier versions of PHP:

If you have a regular expression (I use the POSIX ones almost exclusively since they’re UTF-8 aware whereas the Perl ones were not when last I inquired), and you want to set a range for the number of matches on a particular expression you can use the syntax:

$expr = '[a-zA-Z]{5,50}';        // matches between 5 (incl) and 50 (incl) letters

Now, the problem is: what if you want to have the number of characters in the range be PHP variables that you can set in a configuration file or some such thing? Your first attempt, and what I used in my book, might be:

$expr = "[a-zA-Z]\{$min,$max}";        // double quotes for var expansion

And you would get a wonderfully annoying error message from the PHP engine:

Parse error: syntax error, unexpected ',', expecting '}' in Filename on line 5

No amount of backslashes will fix this problem. It turns out that the PHP parser consumes { and } characters when performing complex variable expansion, so …. all you have to do is add an extra set around each of the variables you wish to expand. PHP leaves the other two alone:

$expr = "[a-zA-Z]{{$min},{$max}}";        // extra { }s are consumed.

And what you are left with is a wonderfully working regular expression.

User:marc: Chipmunk Ninja Technical Articles

Username:
Password:
(or Cancel)