SEO友情链接,js和/或php剥离

时间:2011-01-21 12:39:08

标签: php javascript url seo

我已经看到这是在wordpress上完成的,我无法访问word press:)

但是我需要返回一个url字符串,从中删除任何无效字符并将一些字符转换为适当的字符:)

e.g。

1+ characters should be converted (of the following)

[space]        = [dash] (1 dash) >>> (-)
[underscore]   = [dash] (1 dash) >>> (-)
$str = 'Hello WORLD this is a bad string';
$str = convert_str_to_url($str);
//output//NOTE: caps have are lowercase :)
//hello-world-bad-string

删除常见和无意义的词语,例如“the”,“a”,“in”etccc

如果你有一个gd代码,

至少指出我正确的方向:)

4 个答案:

答案 0 :(得分:4)

答案 1 :(得分:1)

strtr可用于此:

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

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

答案 2 :(得分:0)

我将使用str_replace()函数创建一个函数。例如:

$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;

将以下网站用于特殊字符:http://www.asciitable.com/

答案 3 :(得分:0)

可能是这样的:

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');