Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top