How do I convert '[download file="file.pdf"]File[/download]' into something else?

Ultrus
Ultrus used Ask the Experts™
on
I'm making a wordpress plugin and want the writer to be able to place a bbcode like tag with an attribute that will be replaced with a form, then a link once the form is submitted.

[download file="http://mywebsite.com/theFile.pdf"]The File[/download]

I guess what would help the most right now is how would I convert what's above into:

Download: <a href="http://mywebsite.com/theFile.pdf">The File</a>

Any thoughts? I'm guessing this is a regex question.

Thanks for the assist. :)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
$output = preg_replace('/\[download file="([a-z0-9_]+\.[a-z]+)"\]([^\[]+)\[\/download\]/', '<a href="http://mywebsite.com/$1">$2</a>', $input);

Author

Commented:
Sweet! That works great, and thank you very much!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial