note 91317 deleted from function.preg-replace by danbrown

From: Date: Fri, 05 Jun 2009 14:08:06 +0000
Subject: note 91317 deleted from function.preg-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156394@lists.php.net to get a copy of this message
Note Submitter: oriol dot torras at mobifriends dot com ---- @spcmky, very nice seo string function, I made a modification that could be interesting. If the string contains 'php.net' the function will return 'phpnet', instead of this I want the string to be 'php-net' (other examples: 'web 2.0' -> 'web-2-0'). <?php static public function encodeUrlParam($string){ $string = trim($string); if ( ctype_digit($string) ){ return $string; }else{ // replace accented chars $accents = '/&([A-Za-z]{1,2})(grave|acute|circ|cedil|uml|lig);/'; $string_encoded = htmlentities($string, ENT_NOQUOTES, 'UTF-8'); $string = preg_replace($accents,'$1',$string_encoded); // clean out the rest $replace = array('/([A-Za-z0-9])(\.)([A-Za-z0-9])/', '([\40])', '([^a-zA-Z0-9-])', '(-{2,})'); $with = array('$1-$3','-','','-'); $string = preg_replace($replace, $with, $string); } return strtolower($string); } ?>

« previous php.notes (#156394) next »