Echoing <a> tag with PHP variables involved
I'm looking to echo an hyperlink in a PHP file. The target and text are variables. And no, I can't just make a html file and then echo out the variables. It has to be done with echoing out the statement. I'm having problems with the " " around the target. The first " is okay, but the second is causing problems. Here is 开发者_StackOverflow社区my code.
while($row = mysql_fetch_assoc($result)){
if (!empty($row[adder])) {
echo "<a href=\"/".$row[adder].\"">".$row[adder]."</a>";
}
The problem is the \" after $row["adder'].
any idea why the error:
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home//public_html/folder/index.php on line 116
is coming up??
I'm sure its just a missing " or something..
Thanks, Niall
The backslash needs to be shifted one position to the right. You can see where it goes wrong by the coloring.
Change this line:
echo "<a href=\"/".$row[adder].\"">".$row[adder]."</a>";
To:
echo "<a href=\"/".$row[adder]."\">".$row[adder]."</a>";
Your backslash is one "
too soon:
echo "<a href=\"/".$row[adder]."\">".$row[adder]."</a>";
Try
echo '<a href="'.$row[adder].'">'.$row[adder].'</a>';
精彩评论