note 29639 added to function.preg-replace
| From: | Andy at rack1 dot php dot net | Date: | Wed, 19 Feb 2003 20:19:24 +0000 |
| Subject: | note 29639 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44224@lists.php.net to get a copy of this message | ||
Here's a quick regex for stripping the quotes from the beginning and end of a string, handy in
case you're writing something that needs to parse HTML-style attributes:
$attribute = "'foo'"; /* Note the single quotes */
$expression = "/(^[\"|']|[\"|']$)/";
$newattribute = preg_replace($expression, '', $attribute);
/* $newattribute now contains the string foo, without the single quotes. This won't interfere
with any single or double quotes that happen to be in the middle of the string. */
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+29639
http://master.php.net/manage/user-notes.php?action=delete+29639
http://master.php.net/manage/user-notes.php?action=reject+29639