我想用str_replace
来操作字符串的输出。str_replace不会删除破折号
function wh_alterProductTitle($title, $id = NULL)
{
if ('product' == get_post_type($id))
{
$title = str_replace('Dames', 'wmns', $title);
$title = str_replace('dames', 'wmns', $title);
$title = str_replace('DAMES', 'wmns', $title);
$title = str_replace('Women’s', 'wmns', $title);
$title = str_replace('Womens', 'wmns', $title);
$title = str_replace('Heren', 'mens', $title);
$title = str_replace('HEREN', 'mens', $title);
$title = str_replace('heren', 'mens', $title);
$title = str_replace('-', '', $title);
$title = str_replace(chr(150), '', $title); // endash
$title = str_replace(chr(151), '', $title); // endash
$title = str_replace(['Bijenkorf', 'Zalando', 'NIKE-', 'Adidas', 'Sarenza', 'Filling Pieces', 'Reebok', 'Nike', 'Hardloopschoen', 'New Balance', 'Converse', 'Asics', 'By', 'Beige', 'Sneakers', 'Laag', 'JDsports', 'Trainingschoen', 'Vans', 'Babyschoen', 'Only At JD', 'NIKE', 'Saucony', 'Nubikk'], '', $title);
}
return $title;
}
add_filter('the_title', 'wh_alterProductTitle', 10, 2);
这段代码改变了输出:
Bijenkorf – Adidas Stan Smith W
要:
– Adidas Stan Smith W
我用尽了几许的每个实例在str_replace
,但是,我不能让它删除破折号..
任何帮助,将不胜感激!
见的差异,这种( - )是从我的键盘和这个破折号( - )将复制您的变更 '$标题问题 – Shan
粘贴= str_replace函数( ' - ', '',$标题);' 到'$ title = str_replace(' - ','',$ title);' 不幸的是什么也没发生 – Matthias
检查此:https://eval.in/749792 – Shan