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>";
?>
精彩评论