发布网友
共2个回答
热心网友
<?php
$str='<style>*
{
margin:0;
padding:0;
border:0;
}
body
{
font-family:Verdana, Arial, "宋体";
font-size:12px;
}
strong
{
font-family:"微软雅黑";
font-size:14px;
color:#000;
font-weight:800;
}</style><html>xxxxxx</html><script>var xxxxxx=0;</script>';
$str = preg_replace_callback('/(<style>.*?<\/style>)/is', function($matched){
return preg_replace('/[\s\n]+/is', '', $matched[1]);
}, $str);
echo $str;
exit;
热心网友
<?php
$str='<style>1x xxxxx
abc</style><html>xxxxxx</html><script>xxxxxx</script>';
$matches=array();
preg_match('/<style>([^<]*)<\/style>/i',$str,$matches);
if(isset($matches[1])){
$s=$matches[1];
$s=str_replace(" ","",$s);
$s=str_replace("\n","",$s);
$s=str_replace("\r","",$s);
echo $s;
}
?>
追问我不是要把内容提取出来再替换哦,我要保留整个页面的字符串,但是里面的去掉空格和换行,你这样是把内容提取出来了,