用文字描述我的问题很困难,我会试着给出一个例子:
str = '
lorem ipsum donor sit
';我需要删除除< xyz@abc.com\u0026gt;之外的所有标签. 我们怎样才能在javascript和PHP中做到? 我的PHP解决方案:
class test {
public function keepMailAddresses($text){
$callBack = array($this,'_keepMailAddresses');
return preg_replace_callback('/()/i', $callBack, $text);
}
private function _keepMailAddresses($matches){
return '<'.$matches[2].'>';
}
}
$obj = new test();
echo $obj->keepMailAddresses('
lorem ipsum donor sit
');