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

时间:2013-11-13 06:09:27

标签: javascript php arrays drupal comments

我必须根据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变量放在其中并且它仍然是注释。

阵列:

$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>'),

1 个答案:

答案 0 :(得分:1)

您可以使用

将php嵌入html注释中,就像使用其他任何地方一样
<?php ?>


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