For example, add some script or style to head, or change the contents of the span in the code below?

<head></head><body><span>text</span></body> 

    1 answer 1

    Almost from the enclosed examples

     $html = str_get_html('<head></head><body><span>text</span></body>'); $html->find('head', 0)->innertext = '<script>alert("Test");</script>'; $html->find('span', 0)->innertext = 'New text'; 

    Adding a script is also not difficult to implement:

     $html->find('head', 0)->innertext .= '<script>alert("Test");</script>'; 

    Ps. Pay attention to the point

    • And how to add the script to the head? rather than replace completely with your content - Sdafs Fasafs
    • @SdafsFasafs updated answer - tutankhamun