在数组中使用注释字符构建复杂字符串


Build complex string with comment characters in an array

我必须根据Drupal中的页面名称将JavaScript代码的动态片段添加到多个页面。下面是代码段的示例。我记下了代码片段中数据将更改的位置。我的问题:在代码片段中,我将如何在有 HTML 注释字符的地方添加 php 变量?

JavaScript 代码:

<!--
Activity name of this tag: Kids Product Page **THIS DATA WILL CHANGE****
URL of the webpage where the tag is expected to be placed: http://www.mywebsite.com/thepage/goeshere.php  **THIS DATA WILL CHANGE****
This tag must be placed between the <body> and </body> tags, as close as possible to the opening tag.
Creation Date: 09/05/2013   **THIS DATA WILL CHANGE****
-->
<script type="text/javascript">
var axel = Math.random() + "";
var a = axel * 10000000000000;
document.write('<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');  **THIS DATA WILL CHANGE****
</script>
<noscript>
<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=1?" width="1" height="1" frameborder="0" style="display:none"></iframe>  **THIS DATA WILL CHANGE****
</noscript>
<!-- End of JS Code: Please do not remove -->

有大约 20 个代码片段,我正在考虑创建一个复杂的数组,但上面的注释字符我不确定我是否可以将 php varaible 放在其中,它仍然是一个注释。

数组:

$myData = array(
"kid_page" => array(
"page_name" => "Kids Product Page",
"page_url" => "http://www.mywebsite.com/thepage/goeshere.php",
"create_date" => "09/05/2013",
"docwrite" => '<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>', 
"noscript" => '<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=1?" width="1" height="1" frameborder="0" style="display:none"></iframe>'),
"adult_page" => array(
"page_name" => "Adult Product Page",
"page_url" => "http://www.mywebsite.com/thepage/goeshere.php",
"create_date" => "10/06/2013",
"docwrite" => '<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>', 
"noscript" => '<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=1?" width="1" height="1" frameborder="0" style="display:none"></iframe>'),

您可以将 php 嵌入到 html 注释中,就像在其他任何地方一样,使用

<?php ?>

<!--
    Activity name of this tag: <?php echo $myData['kid_page']['page_name']; ?>
-->