Jump to content

preg_replace


vikramy

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.