note 90316 modified in function.preg-replace by thiago
| From: | thiago@php.net | Date: | Thu, 16 Apr 2009 07:19:26 +0000 |
| Subject: | note 90316 modified in function.preg-replace by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153374@lists.php.net to get a copy of this message | ||
To make seo url from title or any text:
<?php
function CleanFileName( $Raw ){
$Raw = trim($Raw);
$RemoveChars = array( "([\40])" , "([^a-zA-Z0-9-])", "(-{2,})" );
$ReplaceWith = array("-", "", "-");
return preg_replace($RemoveChars, $ReplaceWith, $Raw);
}
echo CleanFileName('whatever $4 sd- -sdf- @ sd 8 as +% sdf ;');
?>
--was--
To make seo url from title or any text:
function CleanFileName( $Raw ){
$Raw = trim($Raw);
$RemoveChars = array( "([\40])" , "([^a-zA-Z0-9-])", "(-{2,})" );
$ReplaceWith = array("-", "", "-");
return preg_replace($RemoveChars, $ReplaceWith, $Raw);
}
echo CleanFileName('whatever $4 sd- -sdf- @ sd 8 as +% sdf ;');
http://php.net/manual/en/function.preg-replace.php