What is wrong with this code?

Discussion in 'PHP' started by !Unreal, Aug 6, 2008.

  1. #1
    This code wont parse. What is wrong with it?

    echo "<a href=\".$row['divxurl'].\"><img src=\"download.gif\"></a>"
    PHP:

     
    !Unreal, Aug 6, 2008 IP
  2. kamm

    kamm Active Member

    Messages:
    32
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    98
    #2
    A couple of backslashes too many..

    Try this:
    echo "<a href=".$row['divxurl']."><img src=\"download.gif\"></a>"
    Code (markup):
     
    kamm, Aug 6, 2008 IP
  3. live-cms_com

    live-cms_com Notable Member

    Messages:
    3,128
    Likes Received:
    112
    Best Answers:
    0
    Trophy Points:
    205
    Digital Goods:
    1
    #3
    echo '<a href="'.$row['divxurl'].'"><img src="download.gif"></a>';
    Code (markup):
     
    live-cms_com, Aug 6, 2008 IP
  4. kamm

    kamm Active Member

    Messages:
    32
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    98
    #4
    Well, there's lots of different ways to skin a cat. Personally I often go for the heredoc method, although you need to be careful about extraneous white space.

    echo <<<EOD
    <a href="{$row['divxurl']}"><img src="download.gif"></a>
    EOD;
    PHP:
     
    kamm, Aug 6, 2008 IP
  5. !Unreal

    !Unreal Well-Known Member

    Messages:
    1,671
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    165
    #5
    You need the backslashes for it to echo the whole line

    Ill try that, thank you.

    Ive not seen this method before, I will give it a go.
     
    !Unreal, Aug 6, 2008 IP