带有特殊字符的PHP preg_replace函数错误


PHP preg_replace function error with special characters

我正在尝试使用preg_replace函数来解析Html页面中的此表:

Tuition.    $13,140   $13,167    $13,167    
Books       $996      $1,176     $1,176

由于表标记,我得到了"未知修饰符't'"错误,我用'~ ~'更改了'/ /'。

但我还是有问题,函数没有更改文本。我认为文本中"$"美元符号的问题,我如何跳过它?我试着去做,但做不到。

这是我的代码:

$price = $html->find('div[id=divctl00_cphCollegeNavBody_ucInstitutionMain_ctl00] table[class=tabular]');
        $price1=$price[0];
        $show=$price1;
        $ch="~".$show->children(1)->children(0)->children(1)."~";
        $show=preg_replace($ch,' ',$show, 1);

感谢

试试这个:$show=preg_replace(str_replace('$',''$',$ch),' ',$show, 1);如果你不能使用preg_quote并且有多个转义符(在这种情况下,$是你的问题),你可以把你的特殊字符放在一个数组中并从中过滤