例如我的页面就像下面的代码。我知道如何提取"这个"从preg_match的字符串,但我如何获得当前页面的源代码作为PHP中的变量。
<body>
<p>I need to find "this" word from "this" string</p>
</body>
答案 0 :(得分:3)
在脚本开头调用ob_start()
,然后在底部调用ob_get_clean()
。它将以字符串形式返回脚本的输出内容,您可以将其存储在变量中。所以,从你的例子:
<?php ob_start(); ?>
<body>
<p>I need to find "this" word from "this" string</p>
</body>
<?php $foo = ob_get_clean(); ?>