note 61319 deleted from function.preg-replace by colder

From: Date: Mon, 18 Jun 2007 19:57:11 +0000
Subject: note 61319 deleted from function.preg-replace by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127679@lists.php.net to get a copy of this message
Note Submitter: leif at solumslekt dot org ---- I've found a use for preg_replace. If you've got eg. a database with persons assiciated with numbers, you may want to input links in a kind of shorthand, like [p=12345], and have it expanded to a full url with a name in it. This is my solution: $expanded_text = preg_replace('/\\[p=(\d+)\\]/e', "\\"<a href=\\\\\\"./test.php?person=$1\\\\\\">\\".get_name($1).\\"</a&>\\"", $short_text); It took me some time to work out the proper number of quotes and backslashes. regards, Leif.

« previous php.notes (#127679) next »