Jump to content

Search text for links and make them to <a href>'s


seksislav

Recommended Posts

Depends how substantial you require it to be. Are all your links going to be http?  Here's an example but it is very simple. If there are specific url's you need to include or you need to validate them as proper links then you will need to let us know.

 

echo preg_replace("#(https?://[^ ]+)#", '<a href="$1">$1</a>', $input);

Link to comment
Share on other sites

No need to capture the match, as the full pattern match is stored in $0. And I would use \S instead of [^ ], to stop the matching at any whitespace character (most importantly a line break). And probably add the i modifier :)

Like I said, the example given was about the most basic it could be (bar perhaps removing the optional s for https). :) Your right I could have used $0, I was actually planning on making the pattern more complicated which would have required the capture group, but then I thought, fuck it, this meets the stated objectives and I need to be at my pool match in half hour.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.