how do i echo a link with text?

Discussion in 'PHP' started by Kurt Whittingham, Mar 18, 2012.

  1. #1
    sorry if the title didnt make sence

    but what i want to do is
    in html you make a link and have a name

    <a href="http://www.link.php">LINK NAME</a>
    HTML:
    but how do i do that in php
    i am trying to get the url that comes from the database to be a link of the title
    
    echo $row['article_name'];
    echo "</td></tr><tr><td>"; 
    echo $row['url'];
    
    PHP:
    so i want the ['url'] to be a link and the ['article name'] to be the text over it.
     
    Kurt Whittingham, Mar 18, 2012 IP
  2. benjaminp

    benjaminp Guest

    Messages:
    1,212
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    230
    #2
    echo "<a href=\"". $row['url'] ."\">". $row['article_name'] ."</a>";
    Code (markup):
    The above should work *I think*. I'm still getting to grips with it myself, but I believe that's correct.
     
    benjaminp, Mar 18, 2012 IP
  3. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #3
    This is correct. I usually use alrternate quotes to do away with those ugly looking slashes though:
    
    echo '<a href="'. $row['url'] .'">'. $row['article_name'] .'</a>';
    
    Code (markup):
     
    samyak, Mar 18, 2012 IP
  4. benjaminp

    benjaminp Guest

    Messages:
    1,212
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    230
    #4
    Ah, so that allows me to not escape quotes. I need to visit this section more often :)
     
    benjaminp, Mar 18, 2012 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    My personal preferance would be:

    echo "<a href=\"{$row['url']}\">{$row['article_name']}</a>";
    PHP:
     
    danx10, Mar 18, 2012 IP