to manipulate the DOM of the current page using PHP?

I would like to know how to manipulate the DOM of the current page using PHP. The explanation is as below:

This is the code in my PHP file:

<div id="edittitle" title="Editing title">
    libxml_use_internal_errors( true );
    $dom=new DOMDocument('1.0','utf-8');
    $dom->loadHTML( $strhtml );
    echo $col->item(0)->nodeValue;

Actually, what I want is putting the whole html code that exists in the current file (the PHP file) in the variable $strhtml (Please focus on the following line of my code: $strhtml=;). Is there any idea about how to do that?

Thanks in advance.


If you really want to you can do this by putting all of your HTML in an output buffer while / before sending it to the browser (the latter can be easily done with output control). Then you can DOM parse the "captured" HTML.

But you should ask yourself what you are really trying to achieve and if this is not better suited for client-side (i.e. Javascript) code.

PHP is a server-side language and is only executed on the server, any DOM manipulations must be handled by client-side Javascript.

Need Your Help

Modules are disabled - but why?

ios module ios8 cocoapods xcode7

I'm struggeling with Modules in a project. Where I use @import I get "Use of '@import' when modules are disabled". But why are they disabled?