0

我想在 php 中的 echo 中使用此代码。

 <div id="ib-main-wrapper" class="ib-main-wrapper">
 <div class="ib-main">
 <a href="#">
 <img src="images/upload/Desert.jpg" data-largesrc="images/upload/Desert.jpg"  
 alt="image01"/><span>Crabbed Age and Youth</span></a>

请建议

4

6 回答 6

8

利用heredoc

echo <<<EOT
 <div id="ib-main-wrapper" class="ib-main-wrapper">
 <div class="ib-main">
 <a href="#">
 <img src="images/upload/Desert.jpg" data-largesrc="images/upload/Desert.jpg"  
 alt="image01"/><span>Crabbed Age and Youth</span></a>
EOT;
于 2013-01-31T10:05:01.473 回答
1

这很简单。试试下面的代码

echo '<div id="ib-main-wrapper" class="ib-main-wrapper">
                <div class="ib-main">
 <a href="#"><img src="images/upload/Desert.jpg" data-largesrc="images/upload/Desert.jpg" alt="image01"/><span>Crabbed Age and Youth</span></a>';
于 2013-01-31T10:04:34.333 回答
1

heredoc 的替代方法是使用输出缓冲区

它们以下列方式工作:

ob_start(); ?>
 <div id="ib-main-wrapper" class="ib-main-wrapper">
     <div class="ib-main">
         <a href="#">
             <img src="images/upload/Desert.jpg" data-largesrc="images/upload/Desert.jpg" alt="image01"/><span>Crabbed Age and Youth</span>
         </a>

    <?php
$result = ob_get_clean();
// you now have the full html in $result, and you can echo it
echo ob_get_clean();
// or just echo it

heredoc 有一个优势 - 您可以在其中使用任何 PHP 代码。

于 2013-01-31T10:08:39.830 回答
0

不知道我明白你的意思,但有两种方法可以做到:

<?php echo '<div id="ib-main-wrapper" class="ib-main-wrapper">
<div class="ib-main">
<a href="#"><img src="images/upload/Desert.jpg" data-largesrc="images/upload/Desert.jpg" alt="image01"/><span>Crabbed Age and Youth</span></a>'; ?>

甚至更好:

<?php
//Insert more PHP code
?>
<div id="ib-main-wrapper" class="ib-main-wrapper">
<div class="ib-main">
<a href="#"><img src="images/upload/Desert.jpg" data-largesrc="images/upload/Desert.jpg" alt="image01"/><span>Crabbed Age and Youth</span></a>
<?php
//Even more PHP code
?>

第二个使在带有语法突出显示的编辑器中更容易阅读。

于 2013-01-31T10:10:12.433 回答
0
echo '<div id="ib-main-wrapper" class="ib-main-wrapper">
 <div class="ib-main">
 <a href="#">
 <img src="images/upload/Desert.jpg" data-largesrc="images/upload/Desert.jpg"  
 alt="image01"/><span>Crabbed Age and Youth</span></a>';
于 2013-01-31T10:05:00.740 回答
0
<?php

$str = <<<EOL
<div id="ib-main-wrapper" class="ib-main-wrapper">
                <div class="ib-main">
 <a href="#"><img src="images/upload/Desert.jpg" data-largesrc="images/upload/Desert.jpg" alt="image01"/><span>Crabbed Age and Youth</span></a>
EOL;

echo $str;
于 2013-01-31T10:06:12.033 回答