0

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

3
  • 4
    There is at least a closing } missing at the end.
    – Sirko
    Commented Jun 30, 2013 at 17:52
  • 1
    At least give us the error message.
    – deceze
    Commented Jun 30, 2013 at 17:55
  • Parse error: syntax error, unexpected $end in CODE on line 7
    – Ankloop
    Commented Jun 30, 2013 at 17:56

2 Answers 2

1

You can either user 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:

<?php
$guide = get_post_meta($post->ID, '_wpb_in_onda', TRUE);
if($guide){
    echo '<div>' . stripslashes(htmlspecialchars_decode($guide)) . '</div>';
}; 
?>
1
  • The 2° code works but the last gives me Parse error: syntax error, unexpected '.' in CODE on line 4. The second code is correct. Thank you
    – Ankloop
    Commented Jun 30, 2013 at 18:12
0

You don't end your if tag. 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.

2
  • Do I have to add <?php endif; ?> ? Sorry but I don't know PHP
    – Ankloop
    Commented Jun 30, 2013 at 18:03
  • @ankloop , depends on your which syntax you want to use. see my answer Commented Jun 30, 2013 at 18:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.