开发者

PHP (Regex) code to remove a Div with a specific ID

How can I get rid of these in a scrapped page using a PHP Regex code to go over the content and replace it with nothing?

<di开发者_如何学编程v id="news-id-245245" style="display:inline;">

I also do not have any other parts of the page where I use an ID for a div, so it will also work if a pattern simply removed all DIVs with an ID tag.

The id of the div is always as follows: "news-id-NUMBER"


Regarding your comment "I am not sure if this even makes sense": Since it works, it makes sense. I simplified your solution a bit; we don't need the parentheses around .*?. (We do need the ? unless there is only a single match in $content.)

$content = preg_replace('/<div id="news-id-.*?" style="display:inline;">/s', '', $content);


I don't think RegEx is an option here, you'll have to call it specifically. For example:

<?php
   echo "<style>#news-id-NUMBER{display:none;}</style>";
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜