php中如何用str_replace替换一个不确定的内容?

2024-12-15 12:34:39
推荐回答(2个)
回答1:

/*
Author: DirCMS Team
Date: 2011/8/5 16:21
*/

$str='dfadfas不要的内容,但该内容不确定,只是在a标签里fadsfdsfadfsdaf';

$str=preg_replace('/(.*?)(.*?)<\/a>(.*?)/i','\\1\\3',$str);

echo $str;
?>

回答2:

$s = "dfadfasfadsfdsfadfsdaf";
str_replace('', '', $s);
str_replace('
', '', $s);