你可以在变量输出中有内部php标签吗?

时间:2014-08-12 22:52:17

标签: php jquery html

你可以在php变量输出中使用内部php标签吗?任何提示都会很棒。谢谢。

代码低于

    <div class="slick-carousel">
      <div><a 
          <?php if(!empty($pp_image_lightbox_title)) { ?>
              data-title="
              <?php if(!empty($image_desc)) { ?>
                  <?php echo htmlentities($image_desc); ?>
              <?php } ?>"<?php } ?> 
              class="fancy-gallery" data-fancybox-group="fancybox-thumb" href="
              <?php echo $image_url[0]; ?>
              "><img src="/wp-content/uploads/2013/06/shutterstock_45145123.jpg" alt="" class="portfolio_img"/>
      </a></div>
      <div><img src="img/lutron_lg.png" alt="Lutron" /></div>
      <div><img src="img/savant_lg.png" alt="Savant" /></div>
      <div><img src="img/elan_lg.png" alt="Elan" /></div>
      <div><img src="img/crestron_lg.png" alt="Crestron" /></div>
      <div><img src="img/rti_lg.png" alt="RTI" /></div>       
      <div><img src="img/cedia_lg.png" alt="Cedia" /></div>
      <div><img src="img/industry_partner_lg.png" alt="Industry Partner" /></div>
      <div><img src="img/amx_lg.png" alt="AMX Inconcert" /></div>
    </div>

1 个答案:

答案 0 :(得分:1)

如果你需要在其中放入一些其他PHP变量,你可以这样做:

$image_content = 'bla bla bla bla'. $your_other_stuff .'bla bla bla';

如果您需要在输出的末尾添加其他内容,您可以执行以下操作:

$image_content = '<div class="slick-carousel">
  <div><a <?php if(!empty($pp_image_lightbox_title)) { ?>data-title="<?php if(!empty($image_desc)) { ?><?php echo htmlentities($image_desc); ?><?php } ?>"<?php } ?> class="fancy-gallery" data-fancybox-group="fancybox-thumb" href="<?php echo $image_url[0]; ?>"><img src="/wp-content/uploads/2013/06/shutterstock_45145123.jpg" alt="" class="portfolio_img"/></a></div>
  <div><img src="img/lutron_lg.png" alt="Lutron" /></div>
  <div><img src="img/savant_lg.png" alt="Savant" /></div>
  <div><img src="img/elan_lg.png" alt="Elan" /></div> ';

$content_at_the_end = ' bla bla bla bla ';

$image_content .= $content_at_the_end;

如果您需要的是实际替换alt =&#34; Lutron&#34;您可以使用本机php函数来执行此操作:

$image_content = '<div class="slick-carousel">
  <div><a <?php if(!empty($pp_image_lightbox_title)) { ?>data-title="<?php if(!empty($image_desc)) { ?><?php echo htmlentities($image_desc); ?><?php } ?>"<?php } ?> class="fancy-gallery" data-fancybox-group="fancybox-thumb" href="<?php echo $image_url[0]; ?>"><img src="/wp-content/uploads/2013/06/shutterstock_45145123.jpg" alt="" class="portfolio_img"/></a></div>
  <div><img src="img/lutron_lg.png" alt="Lutron" /></div>
  <div><img src="img/savant_lg.png" alt="Savant" /></div>
  <div><img src="img/elan_lg.png" alt="Elan" /></div>
  <div><img src="img/crestron_lg.png" alt="Crestron" /></div>
  <div><img src="img/rti_lg.png" alt="RTI" /></div>       
  <div><img src="img/cedia_lg.png" alt="Cedia" /></div>
  <div><img src="img/industry_partner_lg.png" alt="Industry Partner" /></div>
  <div><img src="img/amx_lg.png" alt="AMX Inconcert" /></div>
</div> ';

$new_content = ' alt="new_alt" ';
$image_content = str_replace( 'alt="Lutron"', $new_content, $image_content);

它将取代alt =&#34; Lutron&#34;通过alt =&#34; new_alt&#34;进入你的$ image_content变量。