SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast akstar's Avatar
    Join Date
    Feb 2009
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to hyperlink ?

    here is my code.

    PHP Code:
    <?php

    echo "<b>Website : </font></b>" wordwrap($row['website1'],60,"<br />\n",true) . "</td>";

    mysql_close($con);
    ?>
    The code above only displays the website url in a NORMAL text.
    I would like the user to be able to CLICK on the website text, and take them to the website.

    How do I code that ?
    I know I have to insert <a href ....... ></a> .... but I don't know where.

    Thanks a million for the help provided

  2. #2
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    PHP Code:
      echo "<b>Website : </font></b><a href='".$row['website1']."'>" wordwrap($row['website1'],60,"<br />\n",true) . "</a></td>";  
     
    mysql_close($con); 

  3. #3
    SitePoint Enthusiast akstar's Avatar
    Join Date
    Feb 2009
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi souvikindia,
    thanks for the reply.
    its almost there. I can see the hyperlink in blue colour. Underlined.
    but somehow, its going to www.myOwnDomainName.com/www.theNewWebsite.com

    so it can't seem to link properly.
    any idea how to go about ?
    Thanks

  4. #4
    SitePoint Enthusiast LSC-Rob's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, NSW Australia
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're not storing the URL as "http://www......." in the database (i.e. only storing "www.url...", then you'll need to use:

    PHP Code:
      echo "<b>Website : </font></b><a href='http://".$row['website1']."'>" wordwrap($row['website1'],60,"<br />\n",true) . "</a></td>";  

     
    mysql_close($con); 
    (Note the href='http://)
    Rob G.
    ShopManager - Sales & Repair Business Management Software

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    But what if the url DOES have http:// in it?

    PHP Code:
    $website preg_match('/https?:\/\//'$row['website1']) ? $row['website1'] : ('http://' $row['website1']);
    printf('<b>Website :</b><a href="%1$s" title="%1$s">%2$s</a>'$websitewordwrap($website60"<br />\n"true)); 
    By the way, there isn't really a need for mysql_close() unless in extreme circumstances. Also, CSS can handle the word-wrapping and <b /> tags aren't recommended - again, a CSS approach would be more effective better.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Enthusiast akstar's Avatar
    Join Date
    Feb 2009
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    But what if the url DOES have http:// in it?

    PHP Code:
    $website preg_match('/https?:\/\//'$row['website1']) ? $row['website1'] : ('http://' $row['website1']);
    printf('<b>Website :</b><a href="%1$s" title="%1$s">%2$s</a>'$websitewordwrap($website60"<br />\n"true)); 
    By the way, there isn't really a need for mysql_close() unless in extreme circumstances. Also, CSS can handle the word-wrapping and <b /> tags aren't recommended - again, a CSS approach would be more effective better.
    thanks LSC-Rob.
    yes very good advice arkinstall.
    I am using your code, and it works perfectly!
    THANKS so so much everyone!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •