简体   繁体   English

php解析错误,帮我解决错误

[英]Php parse error, help me fix the mistake

there is a mistake in this code. 该代码有误。 What's the correct code? 什么是正确的代码?

<?php
$guide = get_post_meta($post->ID, '_wpb_in_onda', TRUE);
if($guide){
?>
<div>
<?php echo stripslashes(htmlspecialchars_decode($guide));?>
</div>

Parse error: syntax error, unexpected $end in CODE on line 7 解析错误:语法错误,第7行的CODE中意外的$ end

You can either user if:else:endif; 您可以使用if:else:endif; syntax: 句法:

<?php
$guide = get_post_meta($post->ID, '_wpb_in_onda', TRUE);
if($guide):
?>
<div><?php echo stripslashes(htmlspecialchars_decode($guide));?></div>
<?php endif;?>

or what you are doing, but you need the closing if brace } : 或您正在做什么,但是如果需要大括号}则需要关闭:

<?php
$guide = get_post_meta($post->ID, '_wpb_in_onda', TRUE);
if($guide){
?>
<div><?php echo stripslashes(htmlspecialchars_decode($guide));?></div>
<?}; // this is missing in your code ?>

or you can echo out the HTML as well: 或者您也可以回显HTML:

<?php
$guide = get_post_meta($post->ID, '_wpb_in_onda', TRUE);
if($guide){
    echo '<div>' . stripslashes(htmlspecialchars_decode($guide)) . '</div>';
}; 
?>

You don't end your if tag. 您不会结束if标签。 Next to that it isn't really clean to break out of PHP for some HTML coding, you'd rather use the "echo" command in PHP. 除此之外,对于某些HTML编码来说,打破PHP并不是很干净,您宁愿在PHP中使用“ echo”命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM