我有能力制作我在网上找到的SEO链接的功能,但是使用最新的PHP它因为ereg_replace而无效。 有人可以帮我把它改成preg_replace。
function generate_seo_link($FieldName, &$CurrVal, &$CurrPrm){
//make it lowercase, remove punctuation, remove multiple/leading/ending spaces
$rep = trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',strtolower($CurrVal))));
//convert the spaces to whatever the user wants
//usually a dash or underscore..
//...then return the value.
$CurrVal = str_replace(' ','-',$rep);
}
答案 0 :(得分:3)
您只需将ereg_replace
更改为preg_replace
,就像这样
function generate_seo_link($FieldName, &$CurrVal, &$CurrPrm){
//make it lowercase, remove punctuation, remove multiple/leading/ending spaces
$rep = trim(preg_replace('/ +/',' ',preg_replace('/[^a-zA-Z0-9\s]/','',strtolower($CurrVal))));
//convert the spaces to whatever the user wants
//usually a dash or underscore..
//...then return the value.
$CurrVal = str_replace(' ','-',$rep);
}
对于preg_replace
,您必须使用分隔符封装正则表达式(注意正则表达式中的周围/)。
答案 1 :(得分:1)
让我们看看。将ereg_replace
更改为preg_replace
。你不需要帮助,只需改变它。