0

我将如何在 PHP 中完成这项工作:

$string = "<div id="widget14" class="widget widget-124">
     <a href="http://website.com/page.php?id={$pageurl}"><p><span class="hotspot" onmouseover="tooltip.show('<strong>About Us</strong><br/>Learn about us!');" onmouseout="tooltip.hide();"><img class="images_button" alt="About Image" src="{$image_url}" width="172px"/><br/>About Us</span></p></a>
    </div>";
4

2 回答 2

4

无需 PHP:

<div id="widget14" class="widget widget-124">
   <a href="http://website.com/cgames/"><p><span class="hotspot" onmouseover="tooltip.show('<strong>About Us</strong><br/>Learn about us!');" onmouseout="tooltip.hide();"><img class="images_button" alt="About Image" src="http://www.website.com/images/logo.png" width="172px"/><br/>About Us</span></p></a>
</div>

如果它绝对必须是一个变量:

$string = <<<HTML
    <div id="widget14" class="widget widget-124">
       <a href="http://website.com/cgames/"><p><span class="hotspot" onmouseover="tooltip.show('<strong>About Us</strong><br/>Learn about us!');" onmouseout="tooltip.hide();"><img class="images_button" alt="About Image" src="http://www.website.com/images/logo.png" width="172px"/><br/>About Us</span></p></a>
    </div>
HTML;

Heredoc语法

否则你会用反斜杠卡住转义引号。

于 2012-06-04T22:52:07.123 回答
0
$string = "<div id=\"widget14\" class=\"widget widget-124\">
     <a href=\"http://website.com/cgames/\"><p><span class=\"hotspot\" onmouseover=\"tooltip.show('<strong>About Us</strong><br/>Learn about us!');\" onmouseout=\"tooltip.hide();\"><img class=\"images_button\" alt=\"About Image\" src=\"http://www.website.com/images/logo.png\" width=\"172px\"/><br/>About Us</span></p></a>
    </div>\";

以上应该可以正常工作。

于 2012-06-04T22:59:37.283 回答