izbryte Posted December 10, 2007 Share Posted December 10, 2007 If someone enters an email address or website into a textarea (which then goes to a mySQL database) is there a way to show those links as hyperlinks instead of plain old text when pulled back out ? Quote Link to comment Share on other sites More sharing options...
micah1701 Posted December 10, 2007 Share Posted December 10, 2007 you could do something like this: <?php $string = "here is a string of text including me@domain.com an e-mail address and http://www.somesite.com a web address"; $newString = ""; $mailArray = explode(" ",$string); foreach ($mailArray as $word){ if(ereg('^([-a-zA-Z0-9.]+@[-a-zA-Z0-9]+(\.[-a-zA-Z0-9]+)+)*$', $word)){ $newString.= "<a href=\"mailto:".$word."\">".$word."</a> "; }elseif(substr($word,0,4) == "http"){ $newString.= "<a href=\"".$word."\">".$word."</a> "; }else{ $newString.= $word." "; } } echo $newString; ?> EDIT: FIXED Quote Link to comment Share on other sites More sharing options...
izbryte Posted December 10, 2007 Author Share Posted December 10, 2007 Thank you but I'm still a bit confused. Your code worked great when I tried it out as is but when I pull the text from the database it doesn't show the link. Am I doing something wrong? Here's my code; $contact = stripslashes(nl2br($row['contact'])); $newString = ""; $mailArray = explode(" ",$contact); foreach ($mailArray as $word){ if(ereg('^([-a-zA-Z0-9.]+@[-a-zA-Z0-9]+(\.[-a-zA-Z0-9]+)+)*$', $word)){ $newString.= "<a href=\"mailto:".$word."\">".$word."</a> "; }else{ $newString.= $word." "; } } echo $newString; Quote Link to comment Share on other sites More sharing options...
micah1701 Posted December 10, 2007 Share Posted December 10, 2007 i edited my original post - it should work now Quote Link to comment Share on other sites More sharing options...
izbryte Posted December 10, 2007 Author Share Posted December 10, 2007 thanks so much for helping me but it still isn't working. do you think it could have something to do with the text? Here is an example of what is being pulled from the database: Please send resumes to: My Compnay Jane Doe 12345 My Avenue, Los Angeles, CA 12345 Email: me@mydomain.com Phone: (123) 123-12345 | Fax: (123) 123-12345 Quote Link to comment Share on other sites More sharing options...
izbryte Posted December 17, 2007 Author Share Posted December 17, 2007 Can anyone help me??? PLEASE??!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.