Jump to content

Recommended Posts

I need to turn this

 

$mystring "This can be any txt at all but may contain a url like www.site.com of which needs parsing"

 

into

 

This can be any txt at all but may contain a url like <a href="http://www.site.com target=BlanK>www.site.com</a> of which needs parsing

 

I found the below php code in this section, but it only detects a urls presence within the string, doesnt actually do anything with it

 

if (preg_match('~
	(?:[a-z0-9+.-]+://)?  # A optional resource (http, ftp, etc)
	(?:\w+\.)+            # the host.domain
	\w{2,6}               # the TLD
	\S*                   # an optional path/to/file
	~ix', $mystring)) {
echo "no links, you turkey";
} else {
echo "nice comment";
}

 

If someone can help me with this I will be really happy! Driving me nuts!

 

If you want to go the extra mile, I need it in javascript aswell, but its more important php method works before anything else

Link to comment
https://forums.phpfreaks.com/topic/79067-solved-find-and-parse-url/
Share on other sites

Doesnt output anything, if I take the link out, it prints the text fine

 

Obviously a glitch in code

 

Here, best to use live example and modify until working

 

$str = "dss s sd s www.site.com but may not work";
$str = preg_replace('/(((ftp|http|https):\/\/)?www\.(.*)+\.(.*)+) /','<a href="$1">$1</a>',$str);
echo $str;

 

Hope someone can help

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.