[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

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. :)
0
Ultrus
Asked:
Ultrus
1 Solution
 
thehagmanCommented:
$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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now