Php 如何使用token_get_all查找所有T_INLINE_HTML?
我最近听说了一个名为Php 如何使用token_get_all查找所有T_INLINE_HTML?,php,html,token,Php,Html,Token,我最近听说了一个名为token\u get\u all的函数,我想了解如何从包含php代码和HTML的php文件中获取所有的T\u INLINE\u HTML。例如,像这样的文件: <?php echo "This is my PHP code"; ?> <html> <p>Hello, this is the HTML code I want from token_get_all!</p> </html> 但那没用。我该怎么做呢?下
token\u get\u all
的函数,我想了解如何从包含php代码和HTML的php文件中获取所有的T\u INLINE\u HTML。例如,像这样的文件:
<?php
echo "This is my PHP code";
?>
<html>
<p>Hello, this is the HTML code I want from token_get_all!</p>
</html>
但那没用。我该怎么做呢?下面的代码将过滤掉文件中的标记,只留下内联HTML标记:
$tokens = token_get_all($filecontents);
$tokens = array_filter($tokens, function($token)
{
return $token[0] == T_INLINE_HTML;
});
下面的代码将过滤掉文件中的标记,只留下内联HTML标记:
$tokens = token_get_all($filecontents);
$tokens = array_filter($tokens, function($token)
{
return $token[0] == T_INLINE_HTML;
});
是的,匿名函数!将需要PHP>=5.3,考虑匿名函数!但需要PHP>=5.3