duanpanhuo0618
2013-03-23 22:30
浏览 62
已采纳

怎么能在php中回显方括号[关闭]

I want to echo the following code, but its not working:

<?php
if ( is_page('residenz') ) 
{ echo '[nggallery id=12]'; } 
else if ( is_page('apartment-royal-ii') ) 
{ echo '[nggallery id=13]'; } 
else if ( is_page('apartment-royal-iii') ) 
{ echo '[nggallery id=14]'; } 
else if ( is_page('apartment-royal-iv') ) 
{ echo '[nggallery id=15]'; } 
else if ( is_page('apartment-royal-v') ) 
{ echo '[nggallery id=16]'; } 
else { echo '[nggallery id=11]'; } 
?>

I assume that the problem is in the square brackets.

How can I echo [nggallery id=11] for instance?

Some more info:

The code is executed in a wordpress widget.

This is how I modified the widgets to accept php:

add_filter('widget_text','execute_php',100);
function execute_php($html){
     if(strpos($html,"<"."?php")!==false){
          ob_start();
          eval("?".">".$html);
          $html=ob_get_contents();
          ob_end_clean();
     }
     return $html;
}

EDIT2:

I used this and it works:

<?php
if (1 == 1)
{?>
 [nggallery id=13]
<?php
}
?>

图片转代码服务由CSDN问答提供 功能建议

我想回显以下代码,但它不起作用:

  &lt;?php 
if(is_page('residenz'))
 {echo'[nggallery id = 12]';  } 
else if(is_page('apartment-royal-ii'))
 {echo'[nggallery id = 13]';  } 
else if(is_page('apartment-royal-iii'))
 {echo'[nggallery id = 14]';  } 
else if(is_page('apartment-royal-iv'))
 {echo'[nggallery id = 15]';  } 
else if(is_page('apartment-royal-v'))
 {echo'[nggallery id = 16]';  } 
else {echo'[nggallery id = 11]';  } 
?&gt; 
   
 
 

我认为问题出现在方括号中。

我如何回应[ nggallery id = 11]例如?

更多信息:

代码在wordpress小部件中执行。 \ n

这是我修改小部件以接受php的方法:

  add_filter('widget_text','execute_php',100); 
function execute_php($ html){  
 if(strpos($ html,“&lt;”。“?php”)!== false){
 ob_start(); 
 eval(“?”。“&gt;”。$ html); 
  $ html = ob_get_contents(); 
 ob_end_clean(); 
} 
返回$ html; 
} 
   
 
 

EDIT2:

我使用了它并且它可以工作:

 &lt;?php 
if(1 == 1)
 {?&gt; 
 [nggallery id =  13] 
&lt;?php 
} 
?&gt; 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doulan8054 2013-03-23 22:38
    已采纳

    Use following code for echo the data:

    <?php
    echo htmlentities('[nggallery id=12]');
    ?>
    
    已采纳该答案
    打赏 评论
  • dongzan2740 2013-03-23 22:41

    Square brackets do not need to be escaped. I think that your conditions evaluate to false. See what is the output of the following statement:

    var_dump(is_page['residenz'])
    
    打赏 评论

相关推荐 更多相似问题