note 42822 added to function.preg-replace

From: Date: Sun, 30 May 2004 23:49:17 +0000
Subject: note 42822 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-70322@lists.php.net to get a copy of this message
I'm working on a project that involves tokenizing content. Came up with this little regular expression that strips all leading and trailing non-alphanumeric characters from a string (but leaves "inner" non-alpha numeric characters). $result = preg_replace("/^[^[:alnum:]]+|[^[:alnum:]]+$/", "", $word); For instance: " **joe@email.com** " => "joe@email.com" " ... Phone: 555-555-1234." => "Phone: 555-555-1234" Hope someone finds it useful. ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42822 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42822&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42822&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#70322) next »