Jump to content

Recommended Posts

Hello Everyone,

 

I am a bit new to php already loving it.

 

I am stuck in this can any one help me in this. I am having a pattern like this

 

[url http://www.example.com]Test[/url]

 

I need it to replace like this <a href="http://www.example.com">Test</a>

 

Any help is really appreciated. Thanks.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/186314-preg_replace/
Share on other sites

Thanks you.. I searched and I think I almost found what I need.

 

$replaced = [url http://www.example.com]Test[/url]

 

$replaced = preg_replace ('/\[url(.*?)\](.*?)\[\/url\]/is','<a href="$1">$2</a>', $replaced);

 

Thanks again. I haven't tested fully but this helps a lot..

Link to comment
https://forums.phpfreaks.com/topic/186314-preg_replace/#findComment-983919
Share on other sites

  • 1 month later...

I have strange requirements like these. hope many have answers.

[url http://www.gmail.com]Gmail[/url] should give Gmail which should point to http://www.gmail.com.

 

And also if I type http://www.gmail.com it should be a link.

The first one I could solve easily. but I need that in combination.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/186314-preg_replace/#findComment-1003931
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.