Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2009-05-07
2
235 Views
Last Modified: 2012-05-06
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
Comment
Question by:Ultrus
2 Comments
 
LVL 20

Accepted Solution

by:
thehagman earned 500 total points
ID: 24328124
$output = preg_replace('/\[download file="([a-z0-9_]+\.[a-z]+)"\]([^\[]+)\[\/download\]/', '<a href="http://mywebsite.com/$1">$2</a>', $input);
0
 
LVL 10

Author Closing Comment

by:Ultrus
ID: 31579106
Sweet! That works great, and thank you very much!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question