0

こんにちは、src が preg_replace を使用してコンテンツ内の URL である img タグを削除したいと思います。

元。

    $content = "<center><img src="http://example.net/wp-content/uploads/2012/10/cell-degeneration-contn.jpg" alt="" title="cell-degeneration-contn" width="950" height="272" class="alignnone size-full wp-image-100" /></center><h2>A first-in-class approach to stop & reverse </h2>";

したがって、出力は次のようになります。

    $content="<center></center><h2>A first-in-class approach to stop & reverse </h2>";

しかし、可能であれば最良の出力は次のとおりです。

    $content="A first-in-class approach to stop & reverse ";
4

2 に答える 2

2

preg_match_all()はここで機能しますが、HTML では最も効率的ではありません。

$content = '<center><img src="http://example.net/wp-content/uploads/2012/10/cell-degeneration-contn.jpg" alt="" title="cell-degeneration-contn" width="950" height="272" class="alignnone size-full wp-image-100" /></center><h2>A first-in-class approach to stop & reverse </h2>';

preg_match("/<h2>(.*)<\/h2>/",$content,$matches);
$output = $matches[1];
echo $output;

最も簡単な方法は、strip_tags()を使用することです。

$output = strip_tags($content);
echo $output;
于 2012-11-02T17:30:38.797 に答える
1

この方法でそれを行うことができます:

    $content = "<center><img src='http://example.net/wp-content/uploads/2012/10/cell-degeneration-contn.jpg' alt='' title='cell-degeneration-contn' width='950' height='272' class='alignnone size-full wp-image-100' /></center><h2>A first-in-class approach to stop & reverse </h2>'";
    preg_match("/<h2>(.+)<\/h2>/", $content, $matches);  
    $match = $matches[1];
    echo $match;
于 2012-11-02T17:39:09.953 に答える