3

I'm really new to php and am having trouble debugging the following snippet.

<?php
$hintMaintain = <<< EOT
    <hr />
    <div id="user_hint"> ABC DE <span class="status_strtolower($account['status_value'])">ucfirst($account['status_value'])</span>FGH</div>

    <div style="margin: 0px 74px 0px 74px; text-align: center; height: 66px; width:66px; background: url('img/strtolower($maintain)hint.png') no-repeat;">
        <span style="line-height: 66px; font-size: 36px; color: black;">$countdown</span>
    </div>
EOT;

eval("\$hintMaintain = \"$hintMaintain\";");
?>
<!-- SOME HTML -->

<?php echo $hintMaintain; ?>

This shows a server error. I haven't been able to work this out.

Help? Thanks.

1
  • Big huge stinkin santax error. How did you miss it? Commented Nov 27, 2011 at 17:00

3 Answers 3

3

Try:

<?php
$hintMaintain = '<hr />
<div id="user_hint">
    <p> ABC DE 
         <span class="status_'.strtolower($account['status_value']).'">'.ucfirst($account['status_value']).'</span>
    FGH</p>
</div>

<div style="margin: 0px 74px 0px 74px; text-align: center; height: 66px; width:66px; background: url(\'img/'.strtolower($maintain).'hint.png\') no-repeat;">
    <span style="line-height: 66px; font-size: 36px; color: black;">'.$countdown.'</span>
</div>';
?>
<!-- SOME HTML -->
<?php echo $hintMaintain; ?>
Sign up to request clarification or add additional context in comments.

Comments

2
 <hr />
 <div id="user_hint"> ABC DE 
<span class="status_strtolower(<? =$account['status_value']); ?>">
<? =ucfirst($account['status_value']);?>
</span>FGH</div>
<div style="margin: 0px 74px 0px 74px; text-align: center; height: 66px; width:66px; background: url('img/<?=strtolower($maintain);?>hint.png') no-repeat;">
    <span style="line-height: 66px; font-size: 36px; color: black;"><?=$countdown/></span>
</div>

<? =$something; ?> 

^^^ will output this something.

Comments

1

What are you trying to do?

You are trying to execute HTML as PHP

Look at the phpdocs on eval http://php.net/manual/en/function.eval.php

The first argument must be valid PHP statements.

I think you are trying to cache the content and display it after, look at this: http://php.net/manual/en/function.ob-flush.php

1 Comment

So, adding an 'echo' would work? I am a little confused about this. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.