i have echo error.
code;

echo '<li>'; 
     echo '<div>'; 
     echo '<div class="author-image">'; 
     echo '<img alt="gravatar" src="http://0.gravatar.com/avatar/8a567031a8d520b2f97089e715b64e00?s=50&amp;d=%3Cpath_to_url%3E&amp;r=G" class="avatar avatar-50 photo" height="50" width="50" />'; 
     echo '</div>'; 
     echo '<div class="comment-wrapper">'; 
     echo '<div class="comment-inner">'; 
     echo '<div class="comment-top">'; 
     echo '<div class="comment-author">'; 
     echo '<a href="http://www.outerspiceweb.com" rel="external nofollow" class="url" target="_blank" />'.$yorumlari_cek_yeni['yazan'].'</a>'; 
     echo '</div>'; 
     echo '<div class="comment-text">'; 
     echo '<p>'.$yorumlari_cek_yeni['yorum'].'</p>'; 
     echo '</div>'; 
     echo '</div>'; 
     echo '<div class="comment-bottom">'; 
     echo '<div class="reply">'; 
     echo '</div>'; 
     echo '<div class="comment-meta">'; 
     echo '<a href="#">'.$yorumlari_cek_yeni['tarih'].'</a>'; 
     echo '</div>' 
     echo '<br class="clearer" />'; 
     echo '</div>'; 
     echo '</div>'; 
     echo '</div>'; 
     echo '<br class="clearer" />'; 
     echo '</div>'; 
     echo '</li>';

where is error? :S

Dani AI

Generated

— the immediate PHP parse error was the missing semicolon, which spotted and corrected. Once that is fixed, the next common problems in this snippet are HTML/quote mangling and unescaped user data, not just the single-line syntax error.

Two practical things to check after the semicolon:

  • Make sure attribute values contain plain text (an img src should be a URL only — not an <a> tag pasted into it).
  • Keep string quoting consistent in PHP and avoid prematurely terminating a quoted string; nested HTML anchors and a self-closing anchor before the author variable are signs of misplaced markup. Also always escape user-supplied values to prevent XSS.

A clearer, safer pattern is to build variables, sanitize them, and output a block of HTML (here using heredoc for readability):

$author = htmlspecialchars($author_raw, ENT_QUOTES, 'UTF-8');
$comment = nl2br(htmlspecialchars($comment_raw, ENT_QUOTES, 'UTF-8'));
$gravatar = filter_var($gravatar_url, FILTER_SANITIZE_URL);
$postUrl = filter_var($post_url, FILTER_VALIDATE_URL) ?: '#';

echo <<<HTML
<li>
  <div class="comment">
    <div class="author-image"><img src="$gravatar" alt="gravatar" width="50" height="50"></div>
    <div class="comment-wrapper">
      <div class="comment-author"><a href="$postUrl" rel="nofollow" target="_blank">$author</a></div>
      <div class="comment-text"><p>$comment</p></div>
    </div>
  </div>
</li>
HTML;

Quick debugging tips: run php -l filename.php to lint for syntax errors, and enable error reporting during development (ini_set('display_errors',1); error_reporting(E_ALL);). After fixing the semicolon, view the generated page source to spot malformed HTML (unclosed tags or stray anchor markup inside attributes). These steps resolve the parse error and prevent the subtle HTML/escaping bugs visible in the original replies from and .

Recommended Answers

All 12 Replies

Member Avatar for Member #120589

Is this a test?

Give more details as to the problem. Are you getting an error message, and if so, what is it? If not, is it not displaying correctly?

Post the error message you got.

commented: +++++++= +3

Look at line 21 of your code:

echo '</div>'

You are missing the semi-colon at the end of the line, i.e. like this:

echo '</div>;'
Member Avatar for Member #120589

no not like that :)

like this:

echo '</div>';

Hahaha yep ardav! Doh! :)

Member Avatar for Member #120589

which tutorial?

Haha, what do you suggest? echo 'hello' or die("Couldn't echo 'hello'! The program will quit now."); ?

I've actually seen this in javascript once:

try {
  document.write("something, don't remember");
} catch (e) {
  alert('error!');
}

Just as useless is checking for document.getElementById IMHO, but that's another story.

Missed the ; on line 21

Member Avatar for Member #120589

Ok, is this solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.