database item and apostrophe

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tasteofchaos
    New Member
    • Dec 2009
    • 4

    database item and apostrophe

    Hey guys,

    Small problem...

    On my site:

    <Link removed>

    Apostrophes stop any more text after it showing in link titles.

    For example, on the right hand side half way down the page the album name:

    You're The Designers, We're The Deciders for the band Not Advised.

    if you hover, or check the source - it stops at You.

    The code is:

    Code:
    echo "</td><td class='listingtitle'>Artist: <b></td><td><a href='http://megalyrics.net/search.html?c=".$row[artist]."' alt='View ".$row[artist]." Lyrics' title='View ".$row[artist]." Lyrics'>".$row[artist]."</a></b></td></tr><tr><td class='listingtitle'>Album:</td><td><a href='http://megalyrics.net/search.html?c=".$row[album]."' title='View ".$row[album]." Lyrics' title='View ".$row[album]." Lyrics'>".$row[album]."</a></td></tr><tr><td class='listingtitle'>Views:</td><td><font color='#444444'>".$row[views]."</font></td></tr>";

    Any ideas why it is stopping at the apostrophe in the generated code and how it can be fixed??
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    You need to make sure the quote-marks add up. That the apostrophe in the Artist name isn't messing with the single-quotes that mark the start and end of the string in the HTML markup.
    [code=php]<a title='This is John's name.' ..>[/code]
    There the apostrophe in "John's" will close the string used for the title attribute. The rest of the value would be thrown away as garbage text that doesn't belong. The third single-quote, that you meant to be the end of the string, might even cause further collateral damage, causing the following tags to be ignored as a part of a random string that belongs nowhere.

    You can use the htmlentities function to convert plain-text apostrophes into their HTML equivalents, which you can then safely echo into your markup.
    [code=php]<?php
    $title = "John's name";
    $title = htmlentities($t itle, ENT_QUOTES, 'UTF-8');

    echo "<a title='{$title} ' href='#'>Test</a>";

    // Result: <a title='John&#38 ;#39;s name' href='#'>Test</a>
    ?>[/code]
    &#38;#39; is the HTML equivalent to a single-quote, and will be displayed as such in the output.
    Last edited by Atli; Dec 13 '09, 07:38 PM. Reason: Improved the code.

    Comment

    • clain
      New Member
      • Feb 2007
      • 79

      #3
      yess ..!!! just use Double quotes where there is chance of single quotes...!!

      or Try Escaping the single quote with additional single quote

      Comment

      Working...