phpQuery::markupToPHP PHP Method

markupToPHP() public static method

Converts document markup containing PHP code generated by phpQuery::php() into valid (executable) PHP code syntax.
public static markupToPHP ( string | phpQueryObject $content ) : string
$content string | phpQueryObject
return string PHP code.
    public static function markupToPHP($content)
    {
        if ($content instanceof phpQueryObject) {
            $content = $content->markupOuter();
        }
        /* <php>...</php> to <?php...? > */
        $content = preg_replace_callback('@<php>\\s*<!--(.*?)-->\\s*</php>@s', array('phpQuery', '_markupToPHPCallback'), $content);
        /* <node attr='< ?php ? >'> extra space added to save highlighters */
        $regexes = array('@(<(?!\\?)(?:[^>]|\\?>)+\\w+\\s*=\\s*)(\')([^\']*)(?:&lt;|%3C)\\?(?:php)?(.*?)(?:\\?(?:&gt;|%3E))([^\']*)\'@s', '@(<(?!\\?)(?:[^>]|\\?>)+\\w+\\s*=\\s*)(")([^"]*)(?:&lt;|%3C)\\?(?:php)?(.*?)(?:\\?(?:&gt;|%3E))([^"]*)"@s');
        foreach ($regexes as $regex) {
            while (preg_match($regex, $content)) {
                $content = preg_replace_callback($regex, create_function('$m', 'return $m[1].$m[2].$m[3]."<?php "
					.str_replace(
						array("%20", "%3E", "%09", "&#10;", "&#9;", "%7B", "%24", "%7D", "%22", "%5B", "%5D"),
						array(" ", ">", "	", "\\n", "	", "{", "$", "}", \'"\', "[", "]"),
						htmlspecialchars_decode($m[4])
					)
					." ?>".$m[5].$m[2];'), $content);
            }
        }
        return $content;
    }

Usage Example

Example #1
0
 /**
  * Enter description here...
  * 
  * @param $code
  * @return unknown_type
  */
 public function markupOuterPHP()
 {
     return phpQuery::markupToPHP($this->markupOuter());
 }
All Usage Examples Of phpQuery::markupToPHP