Question: 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">
<b>1</b>
</div>
$strhtml=;
    libxml_use_internal_errors( true );
    $dom=new DOMDocument('1.0','utf-8');
    $dom->validateOnParse=false;
    $dom->loadHTML( $strhtml );
    libxml_clear_errors();
    $col=$dom->getElementsByTagName('b');
    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.

Answer: 
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](https://secure.php.net/manual/en/ref.outcontrol.php)). 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.

<http://callmenick.com/post/basics-javascript-dom-manipulation>