【发布时间】:2014-08-07 12:16:22
【问题描述】:
我想使用preg_replace()删除被特殊字符包围的单词:
$product_name = 'Choose a : giFt ,';
$word = 'gift';
$regex = '/[-:,]?\b'.$word.'\b[-:,]?/i';
if(preg_match($regex, $product_name))
{
$str = preg_replace($regex, "", trim($product_name));
}
echo $str;
输出:
Choose a : ,
如果我的字符串是“Choose a :giFt”,则如果没有空格就可以正常工作。
我的预期输出是
Choose a
【问题讨论】:
标签: php regex string preg-replace