note 29639 deleted from function.preg-replace by sniper

From: Date: Tue, 30 Sep 2003 12:32:19 +0000
Subject: note 29639 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57479@lists.php.net to get a copy of this message
Note Submitter: Andy Chase (monkey(AT)greyledge.net) ---- 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. */

« previous php.notes (#57479) next »