function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
目前我有上述功能,但我有結果:
Hugo-Boss-The-Scent-For-Her-Eau-De-Perfume-Spray-50ml
當我編輯
str_replace('?', 'a', $string);
然后 4711EauDeCologne800ml
如何增加空間?
我需要得到結果:
Hugo Boss The Scent For Her Eau De Perfume Spray 50ml
我只需要洗掉:@^% $ # ??ó ?
上面的代碼。任何人都可以幫我糾正這個功能嗎?
uj5u.com熱心網友回復:
如果我正確理解您的需求,其中一種方法是:
改成
<?php
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
$string2= preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
return str_replace('-', ' ', $string2); // Replaces all hyphens with spaces.
}
// echo clean("Hugo Boss The Scent For Her Eau De Perfume Spray 50ml ???");
?>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/535722.html
標籤:PHPXML
上一篇:在PHP中洗掉字串末尾的重復字符
