Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2002
    Location
    New York State
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Convert email address in string to html

    Hey there:

    Client has written email addresses into a mysql text field. I'd like to have it output to the page so that it shows up as a valid mailto link - now it just spits out the html characters, but browser doesn't recognize as a link. For example, text field contains <a href = "mailto:asl@vassar.edu">asl@vassar.edu</a>. As well, they have other html formatting in the sql text field, like <em>, etc. How can I output this to the page and have that html formatting preserved?

    Thanks very much.

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    I think this is what you're asking...

    PHP Code:
    echo '<a href="'.$data['email'].'">'.$data['email'].'</a>'
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #3
    New Coder
    Join Date
    Jul 2008
    Location
    India
    Posts
    39
    Thanks
    0
    Thanked 2 Times in 2 Posts
    You can also use following method to get what you want:

    PHP Code:
    echo "<a href=\"mailto:".$row['user_email']."\">".$row['user_email']."</a>"

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Personally I like using (s)printf where available. It tends to make it really easy to add additional fields for display. I also like to use double quotations around any attributes, so I'm always escaping data:
    PHP Code:
    printf("<a href=\"mailto:%s\">%s</a>\n"$row['user_email'], $row['user_email']); 
    I guess thats what C has done to me.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New Coder
    Join Date
    Dec 2002
    Location
    New York State
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey:

    Thanks for the replies. Reading my original entry, I was totally unclear though. Basically, the users have written a block of text - a journal description - into a longtext field. So there is a paragraph of text. Inside the paragraph, they have entered in email addresses, surrounded by html formatting:

    "this is a great journal. If you'd like to email the author, you can at <a href='mailto:donhoe@don.com'>donhoe@don.com</a>. Then he'll respond with a thoughful <em>card</em> and send your wife flowers."

    So, I'd like to output the paragraph, and have the html pieces actually display as html.

    Thanks for any help.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This depends on exactly what you want to do, and how the data was inserted. If printing it out directly from the field to the browser keeps the actual characters, it is keeping their conversion counterparts (&amp; &gt; &lt; etc). If you don't need to do any serious matching a simple htmlspecialchars_decode() should convert them back into actual html tags. Be warned though that if there is any other html data it will also be parsed, including any non-empty tags treated as empty (like an </table> without a start <table>). This is why we use things like bbcode tags to take care of special conversions for us without risking format html breakage.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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