Php 按原样输出代码

Php 按原样输出代码,php,html,escaping,Php,Html,Escaping,附加说明 我必须在静态网页的html正文中粘贴3次以下代码,而不是粘贴它和大量代码,我只希望有一行(3次)调用编写代码,如下所示: 我喜欢制作一个php函数,将GoogleAnalitic代码或adsense输出到hmtl页面。。。。hot可将代码格式化为“按原样”输出,并包含所有“”项 以下是要输出的示例代码: <script type="text/javascript"><!-- google_ad_client = "pub-0743213818925076"; /*

附加说明 我必须在静态网页的html正文中粘贴3次以下代码,而不是粘贴它和大量代码,我只希望有一行(3次)调用编写代码,如下所示:


我喜欢制作一个php函数,将GoogleAnalitic代码或adsense输出到hmtl页面。。。。hot可将代码格式化为“按原样”输出,并包含所有“”项

以下是要输出的示例代码:

<script type="text/javascript"><!--
google_ad_client = "pub-0743213818925076";
/* 728x90, date de création 11/02/10 */
google_ad_slot = "9774402576";
google_ad_width = 870;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


我在某个地方读到了关于[data]标签的信息?。。。。这可能是一种方法吗?

如果在变量中包含HTML代码,请使用

echo htmlspecialchars($google_analytics);
有关详细说明,请参阅

如果它还不在变量中,为方便起见,可以使用HEREDOC表示法:

$google_analytics = <<<EOT

<script type="text/javascript"><!--
google_ad_client = "pub-0743213818925076";
/* 728x90, date de création 11/02/10 */
google_ad_slot = "9774402576";
google_ad_width = 870;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


EOT;

echo htmlspecialchars($google_analytics);
$google\u分析=

如果在变量中包含HTML代码,请使用

echo htmlspecialchars($google_analytics);
有关详细说明,请参阅

如果它还不在变量中,为方便起见,可以使用HEREDOC表示法:

$google_analytics = <<<EOT

<script type="text/javascript"><!--
google_ad_client = "pub-0743213818925076";
/* 728x90, date de création 11/02/10 */
google_ad_slot = "9774402576";
google_ad_width = 870;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


EOT;

echo htmlspecialchars($google_analytics);
$google\u分析=

如果您想输出一些HTML代码(并在不解释的情况下查看实际HTML代码),您可以使用以下两者的组合:

  • ”;
    死亡
    

    应该显示HTML代码,而不需要浏览器对其进行解释。

    如果您想输出一些HTML代码(并查看实际的HTML代码而不需要对其进行解释),可以使用以下两者的组合:

    • ”;
      死亡
      

      应该显示HTML代码,而不需要浏览器对其进行解释。

      因为答案是正确的,并且按原样打印代码,因为它没有按我想要的方式执行。也许我没有用正确的方式解释它。所以我找到了一个解决办法。我在代码中使用一个外部php文件,然后在主文件中使用include。这样,我只有一个代码,我可以重复使用很多次,无论如何谢谢

      因为答案是正确的,所以按原样打印代码,这并不是我想要的方式。也许我没有用正确的方式解释它。所以我找到了一个解决办法。我在代码中使用一个外部php文件,然后在主文件中使用include。这样,我只有一个代码,我可以重复使用很多次,无论如何谢谢

      如果您想按原样显示html,那么页面源应该是这样的。如果您想按原样显示html,那么页面源应该是这样的。
      $google_analytics = <<<EOT
      
      <script type="text/javascript"><!--
      google_ad_client = "pub-0743213818925076";
      /* 728x90, date de création 11/02/10 */
      google_ad_slot = "9774402576";
      google_ad_width = 870;
      google_ad_height = 90;
      //-->
      </script>
      <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
      </script>
      
      
      EOT;
      
      echo htmlspecialchars($google_analytics);
      
      $str = <<<HTML
      <script type="text/javascript"><!--
      google_ad_client = "pub-0743213818925076";
      /* 728x90, date de création 11/02/10 */
      google_ad_slot = "9774402576";
      google_ad_width = 870;
      google_ad_height = 90;
      //-->
      </script>
      <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
      </script>
      HTML;
      
      echo '<pre>';
      echo htmlspecialchars($str);
      echo '</pre>';
      die;