0

How can I create a hyper link from following string.

[url =http://google.com] Google [/url] 

it should be replaced with

<a href="http://www.google.com">Google</a>

The anchor tag is structured with the url as the src attribute and the center as a caption

austinbv
  • 9,297
  • 6
  • 50
  • 82
ishaq
  • 65
  • 7

2 Answers2

0

The function that you would want to use is preg_split.

Shamim Hafiz - MSFT
  • 21,454
  • 43
  • 116
  • 176
0

I am assuming you are writing bbcode. If so writing an actual parser would be faster but if you just want to do search and replace something like

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

I cannot remember the jsfiddle like site that lets you show regexp so if someone know it please leave it in the comments.

Also if you are gonna just copy and paste my code into your bbcode seach and replace file... DONT it's vulnerable to xss injection and really not an amazing expression it just is an example.

austinbv
  • 9,297
  • 6
  • 50
  • 82