Hi, I remember there is a solution to the problem of quotations when using echo because the echo feature thinks you want to stop the echo but in fact it is part of the essential code. For example I have an array of names and links. And I want to code it using PHP so that each name is clickable with its respective link. We all know the code for a link is: <a href="http://vintageguitarpro.com">Vintage Guitars</a> Now when I am coding I need to do this: echo "<a href="" IT DOES NOT LIKE THIS DOUBLE QUOTATION TOGETHER echo $row['link']; echo "">" IT DOES NOT LIKE THIS DOUBLE QUOTATION TOGETHER echo £row['name']; echo "</a>" I remember there is a trick to get around this coding issue but i have forgotten it. What is the trick, please? Thanks.
echo 'WORDS...STUFF' . $variable . 'MORE WORDS'; would output WORDS...STUFFVARIABLEMORE WORDS and echo 'WORDS...STUFF ' . $variable . ' MORE WORDS'; would output WORDS...STUFF VARIABLE MORE WORDS See the spaces in there? So your line would be: echo '<a href="' . $row['link'] . '">' . $row['name'] . '</a>';
Really - just use proper syntax - ie, you start an echo with ' (single quote), and escape out of the echo-state to add a variable, with concatenation. As shown in the example above. If you need to use the same quote in your string, use an escape: echo '<a href="somelinkhere.com">This person\'s name</a>'; PHP:
@PoPSiCLe has it right, in that you're better off using singles for that, escaping the single quote if need be (which is rare). Singles are just a hair faster than doubles too since they aren't spending time scanning for variables or escape codes. Likewise, STOP using multiple echo statements to do the job of ONE... and if you comma delimit it's a hair faster, more predictable and uses less memory than a string addition. echo '<a href="', $row['link'], '">', $row['name'], '</a>'; Code (markup):
Also, a small bit of help, I'm not sure you're doing it, OP, you can use a program with good syntax highlighting, that will instantly change the coloring of your code as soon as you screw up something because you forgot to escape a character or used the wrong symbol. There's notepad++ for instance, as well as many other programs