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

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. :)
LVL 10
UltrusAsked:
Who is Participating?
 
thehagmanConnect With a Mentor Commented:
$output = preg_replace('/\[download file="([a-z0-9_]+\.[a-z]+)"\]([^\[]+)\[\/download\]/', '<a href="http://mywebsite.com/$1">$2</a>', $input);
0
 
UltrusAuthor Commented:
Sweet! That works great, and thank you very much!
0
All Courses

From novice to tech pro — start learning today.