本文整理汇总了PHP中PHPParser::getPhpChunks方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPParser::getPhpChunks方法的具体用法?PHP PHPParser::getPhpChunks怎么用?PHP PHPParser::getPhpChunks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPParser
的用法示例。
在下文中一共展示了PHPParser::getPhpChunks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPageTitle
public static function getPageTitle($filesrc, $prolog = false)
{
if ($prolog === false) {
$chunks = PHPParser::getPhpChunks($filesrc, 1);
if (!empty($chunks)) {
$prolog =& $chunks[0];
} else {
$prolog = '';
}
}
$title = false;
if ($prolog != '') {
if (preg_match("/\\\$APPLICATION->SetTitle\\s*\\(\\s*\"(.*?)(?<!\\\\)\"\\s*\\);/is", $prolog, $regs)) {
$title = UnEscapePHPString($regs[1]);
} elseif (preg_match("/\\\$APPLICATION->SetTitle\\s*\\(\\s*'(.*?)(?<!\\\\)'\\s*\\);/is", $prolog, $regs)) {
$title = UnEscapePHPString($regs[1]);
} elseif (preg_match("'<title[^>]*>([^>]+)</title[^>]*>'i", $prolog, $regs)) {
$title = $regs[1];
}
}
if (!$title && preg_match("'<title[^>]*>([^>]+)</title[^>]*>'i", $filesrc, $regs)) {
$title = $regs[1];
}
return $title;
}
示例2: ParseFileContent
function ParseFileContent($filesrc, $params = array())
{
/////////////////////////////////////
// Parse prolog, epilog, title
/////////////////////////////////////
$filesrc = trim($filesrc);
$prolog = $epilog = '';
$php_doubleq = false;
$php_singleq = false;
$php_comment = false;
$php_star_comment = false;
$php_line_comment = false;
$php_st = "<" . "?";
$php_ed = "?" . ">";
if ($params["use_php_parser"] && substr($filesrc, 0, 2) == $php_st) {
$phpChunks = PHPParser::getPhpChunks($filesrc);
if (!empty($phpChunks)) {
$prolog = $phpChunks[0];
$filesrc = substr($filesrc, strlen($prolog));
}
} elseif (substr($filesrc, 0, 2) == $php_st) {
$fl = strlen($filesrc);
$p = 2;
while ($p < $fl) {
$ch2 = substr($filesrc, $p, 2);
$ch1 = substr($ch2, 0, 1);
if ($ch2 == $php_ed && !$php_doubleq && !$php_singleq && !$php_star_comment) {
$p += 2;
break;
} elseif (!$php_comment && $ch2 == "//" && !$php_doubleq && !$php_singleq) {
$php_comment = $php_line_comment = true;
$p++;
} elseif ($php_line_comment && ($ch1 == "\n" || $ch1 == "\r" || $ch2 == "?>")) {
$php_comment = $php_line_comment = false;
} elseif (!$php_comment && $ch2 == "/*" && !$php_doubleq && !$php_singleq) {
$php_comment = $php_star_comment = true;
$p++;
} elseif ($php_star_comment && $ch2 == "*/") {
$php_comment = $php_star_comment = false;
$p++;
} elseif (!$php_comment) {
if (($php_doubleq || $php_singleq) && $ch2 == "\\\\") {
$p++;
} elseif (!$php_doubleq && $ch1 == '"') {
$php_doubleq = true;
} elseif ($php_doubleq && $ch1 == '"' && substr($filesrc, $p - 1, 1) != '\\') {
$php_doubleq = false;
} elseif (!$php_doubleq) {
if (!$php_singleq && $ch1 == "'") {
$php_singleq = true;
} elseif ($php_singleq && $ch1 == "'" && substr($filesrc, $p - 1, 1) != '\\') {
$php_singleq = false;
}
}
}
$p++;
}
$prolog = substr($filesrc, 0, $p);
$filesrc = substr($filesrc, $p);
} elseif (preg_match("'(.*?<title>.*?</title>)(.*)\$'is", $filesrc, $reg)) {
$prolog = $reg[1];
$filesrc = $reg[2];
}
$title = PHPParser::getPageTitle($filesrc, $prolog);
$arPageProps = array();
if (strlen($prolog)) {
if (preg_match_all("'\\\$APPLICATION->SetPageProperty\\(([\"\\'])(.*?)(?<!\\\\)[\"\\'] *, *([\"\\'])(.*?)(?<!\\\\)[\"\\']\\);'i", $prolog, $out)) {
foreach ($out[2] as $i => $m1) {
$arPageProps[UnEscapePHPString($m1, $out[1][$i])] = UnEscapePHPString($out[4][$i], $out[3][$i]);
}
}
}
if (substr($filesrc, -2) == "?" . ">") {
if (isset($phpChunks) && count($phpChunks) > 1) {
$epilog = $phpChunks[count($phpChunks) - 1];
$filesrc = substr($filesrc, 0, -strlen($epilog));
} else {
$p = strlen($filesrc) - 2;
$php_start = "<" . "?";
while ($p > 0 && substr($filesrc, $p, 2) != $php_start) {
$p--;
}
$epilog = substr($filesrc, $p);
$filesrc = substr($filesrc, 0, $p);
}
}
return array("PROLOG" => $prolog, "TITLE" => $title, "PROPERTIES" => $arPageProps, "CONTENT" => $filesrc, "EPILOG" => $epilog);
}