怎么能在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
}
?>

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

  &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; 
  code>  pre> 
 
 

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

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

更多信息: p>

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

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

  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; 
} 
  code>  pre> 
 
 

EDIT2: p>

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

 &lt;?php 
if(1 == 1)
 {?&gt; 
 [nggallery id =  13] 
&lt;?php 
} 
?&gt; 
  code>  pre> 
  div>

Use following code for echo the data:

<?php
echo htmlentities('[nggallery id=12]');
?>

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'])