💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
通常情况下可以使用`echo`输出 HTML 页面 编辑`/home/project/html.php` ~~~php <?php $highlight = true; echo "<html> <body> <p".($highlight ? " class='highlight'" : '')."> This is a paragraph </p> </body> </html>"; ~~~ 命名行执行 ~~~bash php html.php ~~~ 由于在一对开始和结束标记之外的内容都会被 PHP 解析器忽略,我们可以在 HTML 中需要使用 PHP 的地方在执行 PHP 程序,因此,上面例子可以写成 ~~~php <?php $highlight = true; ?> <html> <body> <p <?=$highlight ? "class='highlight'" : ''?>> This is a paragraph </p> </body> </html> ~~~ 命名行执行 ~~~bash php html.php ~~~ 两次执行的结果是一样的,因此可以使用第二种方式将 PHP 代码嵌入到 HTML 中,避免使用`echo`输出整段 html 代码。