SEO Friendly links, js and/or php stripping

怎甘沉沦 提交于 2019-12-06 23:11:29
Damiqib

strtr can be used for this:

$replace = array(
   ' ' => '-',
   '_' => '-',
   'the' => '',
   ...
);

$string = strtr($string, $replace);

I would create a function with the str_replace() function. For example:

$str = 'Sentence with some words';
$str = strtolower($str);

$searchNone = array('the', 'a', 'in');
$replaceNone = '';

$str = str_replace($searchNone, $replaceNone, $str);

$search = array(chr(32)); //use ascii
$replace = '-';    

$str = str_replace($search, $replace, $str);

echo $str;

Use the following site for the special chars: http://www.asciitable.com/.

Maybe something like:

function PrettyUri($theUri)
{
    $aToBeReplace = array(' then ', ' the ', ' an '
    , ' a ', ' is ', ' are ', ' ', '_');
    $aReplacements = array(' ', ' ', ' '
    , ' ', ' ', ' ', '-', '-');
    return str_replace($aToBeReplace, $aReplacements, strtolower($theUri));
}


echo  PrettyUri('Hello WORLD this is a bad string');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!