Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Convert text URL's in a string to an HTML link

Asked Modified Viewed 3,152 times
F
Frank2012
F
Frank2012 10
  • Junior Member, joined since
  • Contributed 12 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
asked
Junior Member

I come and give this code for all php programmers

<?php
function to_link($string){
return preg_replace("~(http|https|ftp|ftps)://(.*?)(\s|\n|[,.?!](\s|\n)|$)~", '<a href="$1://$2">$1://$2</a>$3',$string);
}

$html = 'This line of text has three urls: http://phpsnips.com http://yahoo.com and http://google.com';

echo to_link($html, TRUE);
?>
0 replies

2 posts

M
max_powers
M
  • Newbie, joined since
  • Contributed 1 post on the community forums.
answered
Newbie

Hello Frank2012,

Where can I fill in the code ??

Cheers Simon
0 replies
F
Falk
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
answered
Super Admin

Fill in what code?, sorry I am confused here, what are you trying to do?
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 2 posts
  • Votes 0 votes
  • Topic users 3 members

3 participants

F
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
F
F
Frank2012 10
  • Junior Member, joined since
  • Contributed 12 posts on the community forums.
  • Started 6 threads in the forums
  • Started this discussions
M
M
  • Newbie, joined since
  • Contributed 1 post on the community forums.

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet