如何用php删除特定的html元标记?

时间:2016-07-19 18:30:10

标签: php html remove-if

我想这样:
如果 php在html源代码中找到此特定元标记,则从标题中删除:

<meta property="og:video:type" content="application/x-shockwave-flash" /> <meta property="og:video" content="https://www.neocsatblog.info/jwplayer/player.swf?file=&autostart=true&skinName=newtube&skinURL=https%3A%2F%2Fneocsatblog.info%2Fskinning-sdk%2Ffive%2Fnewtube%2Fnewtube.xml" />

我试过这种方式,但是没有工作:

if ( $fullmeta == '<meta property="og:video:type" content="application/x-shockwave-flash" /> <meta property="og:video" content="https://www.neocsatblog.info/jwplayer/player.swf?file=&autostart=true&skinName=newtube&skinURL=https%3A%2F%2Fneocsatblog.info%2Fskinning-sdk%2Ffive%2Fnewtube%2Fnewtube.xml" />') {
     $fullmeta="";  
   }

声明完整元数据的完整代码块:

<? 
 $video_url = get_field('video_urlasd');
if (isset($video_url) && $video_url !== "https://") {
  $meta1='<meta property="og:video:type" content="application/x-shockwave-flash" />';
  $skinURL="https://neocsatblog.info/skinning-sdk/five/newtube/newtube.xml";
  $meta2=' <meta property="og:video" content="https://www.neocsatblog.info/jwplayer/player.swf?file='.urlencode($video_url).'&autostart=true&skinName=newtube&skinURL='.urlencode($skinURL).'" />';
  $fullmeta=$meta1.$meta2;
  echo $fullmeta;
  }else{
      echo chop($fullmeta,"asd");
  }
   if ( $fullmeta == '<meta property="og:video:type" content="application/x-shockwave-flash" /> <meta property="og:video" content="https://www.neocsatblog.info/jwplayer/player.swf?file=&autostart=true&skinName=newtube&skinURL=https%3A%2F%2Fneocsatblog.info%2Fskinning-sdk%2Ffive%2Fnewtube%2Fnewtube.xml" />') {
     echo $fullmeta="";  
   }
  ?>

我不知道为什么,因为在HTML源代码中我发现它并且看起来和我复制的一样!

2 个答案:

答案 0 :(得分:0)

你可以使用str_replace。

$fullmeta = '<meta property="og:video:type" content="application/x-shockwave-flash" /> <meta property="og:video" content="https://www.neocsatblog.info/jwplayer/player.swf?file=&autostart=true&skinName=newtube&skinURL=https%3A%2F%2Fneocsatblog.info%2Fskinning-sdk%2Ffive%2Fnewtube%2Fnewtube.xml" />';
$html_without_crap =  str_replace($fullmeta,"",$Where_it_needs_to_look);

PHP文档:http://php.net/manual/en/function.str-replace.php

答案 1 :(得分:0)

替换代码的这一部分

if (isset($video_url) && $video_url !== "https://") {

用这个

if (!empty($video_url) && $video_url !== "https://") {