How would I delete all code or text before the <html> tag with a php code?

Asking because with OpenX no precaution of any kind seems to work, and injections keep turning up, but all before the <html> tag.

I tried this: $fullcode = strstr($fullcode, ''); to remove anything before <html>. (And more that didn't work.)

Hope someone can help me.

有帮助吗?

解决方案

You can use a regexp with positive lookahead:

<?php
$html = "text before html<html>text after html";
$html = preg_replace('/^.*(?=<html>)/i', '', $html);
print $html;

Prints:

<html>text after html
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top