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

2
  • possible duplicate of Best way to parse bbcode Commented Apr 18, 2011 at 5:11
  • That post is tagged cakePHP also. I think considering Raw PHP, this post can stay. Commented Apr 18, 2011 at 5:31

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

The function that you would want to use is preg_split.

1 Comment

I don't see where you're going with that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.