just a few "" issues.

Discussion in 'Web Design and Development' started by jo0, May 9, 2010.

  1. jo0 macrumors regular

    Joined:
    Nov 25, 2009
    Location:
    Seattle, WA
    #1
    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
     

    Attached Files:

  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
  3. C64 macrumors 65816

    C64

    Joined:
    Sep 3, 2008
    #3
    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
    ?>
     

Share This Page