如何在PHP中正确打印此标记

时间:2013-02-10 03:43:26

标签: php html

如何在php中打印这个标记?

<a href="javascript:AddItem('$node->title')" class="showmessage"
OnClick="show_alert()"><img class="atwatw" src="/files/button.gif" border="0" /></a>

我试过这个但是虚无... ....

<?php print '<a href="javascript:AddItem(\'' . $node->title') . '" class="showmessage"
OnClick="show_alert()">' . '<img class="atwatw" src="/files/button.gif" border="0" /></a>' ?>

3 个答案:

答案 0 :(得分:0)

如果你必须将它包含在php标签中:

<?php print '<a href="javascript:AddItem(\'' . $node->title  . '\')" class="showmessage" OnClick="show_alert()"><img class="atwatw" src="/files/button.gif" border="0" /></a>' ?>

如果不是:

<a href="javascript:AddItem('<?=$node->title?>')" class="showmessage" OnClick="show_alert()"><img class="atwatw" src="/files/button.gif" border="0" /></a>

答案 1 :(得分:0)

<?php echo '<a href="javascript:AddItem(\'' . $node->title .'\')" class="showmessage"
OnClick="show_alert()"><img class="atwatw" src="/files/button.gif" border="0" /></a>'; ?>

答案 2 :(得分:0)

您可以从PHP源代码中获取HTML代码,例如

//PHP code
?>

<a href="javascript:AddItem('<?php $node->title; ?>')" class="showmessage"
OnClick="show_alert()"><img class="atwatw" src="/files/button.gif" border="0" /></a>

<?php
//Continue with your PHP here

现在,如果你想在PHP中使用它,那么可以使用printf

printf("<a href=\"javascript:AddItem('%s')\" class=\"showmessage\"
OnClick=\"show_alert()\"><img class=\"atwatw\" src=\"/files/button.gif\" border=\"0\" /></a>",$node->title);

更多的逃脱角色版本:

printf('<a href="javascript:AddItem(\'%s\')" class="showmessage"
OnClick="show_alert()"><img class="atwatw" src="/files/button.gif" border="0" /></a>',$node->title);
相关问题