File code/PHTML.php
class Taeluf\PHTML
Makes DUMDocument... less terrible, but still not truly good
Constants
Properties
-
protected string $src;
The source HTML + PHP code -
protected string $cleanSrc;
The source code with all the PHP replaced by placeholders -
protected array $php;
[ 'phpplaceholder' => $phpCode, 'placeholder2' => $morePHP ] -
protected $phpAttrValue;
A random string used when adding php code to a node's tag declaration. This string is later removed during output()
Methods
-
public function __construct($html)
Create a DOMDocument, passing your HTML + PHP to__construct
. -
public function placeholder(string $string): string
get a string placeholder for a block of code. This placeholder, if inserted into the doc, will be replace by the original code on render -
public function codeFromPlaceholder(string $placeholder): string
Get the code that's represented by the placeholder -
public function phpPlaceholder(string $enclosedPHP): string
Get a placeholder for the given block of code
Intention is to parse a single '' and not ''
When used as intended, will return a single 'word' that is the placeholder for the given code -
public function fillWithPHP(string $codeWithPlaceholders): string
Decode the given code by replacing PHP placeholders with the PHP code itself -
public function __toString()
See output() -
public function output($withPHP=true)
Return the decoded document as as tring. All PHP will be back in its place -
public function hide_own_tag($htn)
-
public function fill_php($html, $withPHP=true)
-
public function xpath($xpath,$refNode=null)
get the results of an xpath query as array -
public function addPhpToTag($node, $phpCode)
Set an attribute that will place PHP code inside the tag declartion of a node.
Basically:<node phpCodePlaceholder>
, which pHtml will later convert to<node <?='some_stuff'?>>
.
This avoids problems caused by attributes requiring a=""
, whichDOMDocument
automatically places. -
public function insertCodeBefore(\DOMNode $node, $phpCode)
-
public function insertCodeAfter(\DOMNode $node, $phpCode)
-
public function cleanHTML($html)
-
public function restoreHtml($html)
-
public function __get($param)
-
public function replaceNode(\DOMNode $node, string $with_str)
Replace a node