首页 > 解决方案 > 如何获取 PHP 标签之间的函数的 HTML 内容?

问题描述

这是一个简单的问题,但我从未见过解决它的方法。我想将我的 HTML 传递给 PHP 标签之间的函数

例子:

<?php $thisVar = ?>
    <h2>Here is my desired HTML<h2>
    <p>Here is my desired HTML<p>
<?php ; callFunction($thisVar);?>

我知道这是不可能的,所以我做了这样的事情:

<?php $thisVar = '
  <h2>Here is my desired HTML<h2>
  <p>Here is my desired HTML<p>
'; callFunction($thisVar);?>

甚至

<?php callFunction('
  <h2>Here is my desired HTML<h2>
  <p>Here is my desired HTML<p>
');?>

最后两个示例有效,但是当我使用长 HTML 作为变量时,它变得杂乱无章。有没有办法像第一个例子那样做?在所需的 HTML 变量之前和之后打开和关闭 PHP 标记?

谢谢!

标签: php

解决方案


推荐阅读