note 61319 added to function.preg-replace
| From: | leif at solumslekt dot org | Date: | Tue, 31 Jan 2006 16:24:29 +0000 |
| Subject: | note 61319 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102768@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 62.101.198.25
Probable Submitter: 62.16.183.238
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61319
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61319&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61319&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61319&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61319&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61319&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61319&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61319&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61319&report=yes
Search -- http://master.php.net/manage/user-notes.php