note 90485 added to function.preg-replace
| From: | spcmky at gmail dot com | Date: | Fri, 24 Apr 2009 14:15:54 +0000 |
| Subject: | note 90485 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153682@lists.php.net to get a copy of this message | ||
Using this for SEO urls. I had to modify it a bit to get through the word wrap. Pretty sure you can
one line it a lot of it.
<?php
public static 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('([\40])','([^a-zA-Z0-9-])','(-{2,})');
$with = array('-','','-');
$string = preg_replace($replace,$with,$string);
}
return strtolower($string);
}
?>
----
Server IP: 72.55.140.6
Probable Submitter: 207.253.180.96
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/90485
Del: integrated -- https://master.php.net/note/delete/90485/integrated
Del: useless -- https://master.php.net/note/delete/90485/useless
Del: bad code -- https://master.php.net/note/delete/90485/bad+code
Del: spam -- https://master.php.net/note/delete/90485/spam
Del: non-english -- https://master.php.net/note/delete/90485/non-english
Del: in docs -- https://master.php.net/note/delete/90485/in+docs
Del: other reasons-- https://master.php.net/note/delete/90485
Reject -- https://master.php.net/note/reject/90485
Search -- https://master.php.net/manage/user-notes.php