Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jo0

macrumors regular
Original poster
Nov 25, 2009
224
0
Seattle, WA
so im trying to pass some info through with a value="hello world" that is constructed in a php file.

works great till i try to add links using a href="link" obviously it stops it at the next " and thats fails to render the remaining. but if i use ' then it breaks the php code thinking my #'s and // are comments.

i uploaded a pic of the code in question. any advice or leads would be great.


thanks,

j
 

Attachments

  • Screen shot 2010-05-09 at 1.00.36 AM.png
    Screen shot 2010-05-09 at 1.00.36 AM.png
    24.4 KB · Views: 110
You need to escape the " with a backspace, like so:

PHP:
echo "<a href=\"http://...\">link</a>";

Alternatively, you can use a single apostrophe to display HTML, so you won't have to escape every double apostrophe:

PHP:
echo '<a href="http://...">link</a>';

The same goes for escaping single apostrophes:

PHP:
echo 'That\'s right';

But even cleaner, better and easier is to display large chunks of HTML outside of PHP, without the echo function. Example:

PHP:
<?php
// some stuff
?>
<a href="http://..">this is a link <?php echo $variable; ?></a>
<?php
// some more php stuff
?>

If you enable PHP short tags in the php.ini you can even shorten that:

PHP:
<?
// some stuff
?>
<a href="http://..">this is a link <?=$variable;?></a>
<?
// some more php stuff
?>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.