note 91317 added to function.preg-replace
| From: | oriol dot torras at mobifriends dot com | Date: | Fri, 05 Jun 2009 14:06:49 +0000 |
| Subject: | note 91317 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156393@lists.php.net to get a copy of this message | ||
@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);
}
?>
----
Server IP: 80.64.47.13
Probable Submitter: 92.56.48.247
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/91317
Del: integrated -- https://master.php.net/note/delete/91317/integrated
Del: useless -- https://master.php.net/note/delete/91317/useless
Del: bad code -- https://master.php.net/note/delete/91317/bad+code
Del: spam -- https://master.php.net/note/delete/91317/spam
Del: non-english -- https://master.php.net/note/delete/91317/non-english
Del: in docs -- https://master.php.net/note/delete/91317/in+docs
Del: other reasons-- https://master.php.net/note/delete/91317
Reject -- https://master.php.net/note/reject/91317
Search -- https://master.php.net/manage/user-notes.php