开发者

Problem echoing this line in PHP

开发者 https://www.devze.com 2023-02-18 04:19 出处:网络
I am having trouble ec开发者_高级运维hoing this line. Is anyone willing to help? echo \'<li><a href=\"http://stackoverflow.com/thread-\'.$row->tid.\'-1-1.html\'\">\'.$row->subject.\

I am having trouble ec开发者_高级运维hoing this line. Is anyone willing to help?

echo '<li><a href="http://stackoverflow.com/thread-'.$row->tid.'-1-1.html'">'.$row->subject.'</a></li>';


As your string is enclosed in single-quotes, you have to close the quotes, concatenate the variables, and re-open the quotes :

echo '<li><a href="http://stackoverflow.com/thread-'
  . $row->tid
  . '-1-1.html">'
  . $row->subject
  . '</a></li>';

(split over several lines to improve readability)


Else, you could use a double-quoted string, to have variables interpolation -- escaping the double-quotes that are inside the string :

echo "<li><a href=\"http://stackoverflow.com/thread-{$row->tid}-1-1.html\">{$row->subject}</a></li>";


Your quotes are mismatched.

....'-1-1.html">'....


<?php

echo <<<_HTML_

<li>
    <a href="http://stackoverflow.com/thread-{$row->tid} 1-1.html">{$row->subject}</a>
</li>

_HTML_;

?>


You are echoing one single quote too much in the middle of this part: '-1-1.html'">'. This single quote is currently closing the string and will result in a parse error.

If your editor is supporting syntax highlighting, you will be able to notice a difference in colour after this quote.

To solve this problem, change this your code to:

echo '<li><a href="http://stackoverflow.com/thread-'.$row->tid.'-1-1.html">'.$row->subject.'</a></li>';


?>
<li>
 <a href="http://stackoverflow.com/thread-<?=$row->tid?>-1-1.html">
   <?=$row->subject?>
 </a>
</li>


like this:

echo '<li><a href="http://stackoverflow.com/thread-'.$row->tid.'-1-1.html">'.$row->subject.'</a></li>'; 
0

精彩评论

暂无评论...
验证码 换一张
取 消