Search code examples
phpopenx

Remove code before <html> tag


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.


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