By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,053 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,053 IT Pros & Developers. It's quick & easy.

translate string to function arguments

P: n/a
I have this:

<headline size="2" color="#000000">Hello World!</headline>

I have already done all the coding to pass this to a PHP function this way:

function headline($content){
print "<span class='headline'>$content</span>";
}

So the <headline...> example would result in:

<span class='headline'> Hello World!</span>

So far so great. But you might have noticed the arguments in the original
string? I want to pass those! I would prefer to have them this way:

headline("Hello World", "color=#000000", "size=2");

And then extrat them with func_get_arg(). But how do I translate a string to
seperated arguments for a function?

Thanks for any suggestions!

--
Sandman[.net]
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Sandman wrote:
I have this:

<headline size="2" color="#000000">Hello World!</headline>

I have already done all the coding to pass this to a PHP function this way:

function headline($content){
print "<span class='headline'>$content</span>";
}

So the <headline...> example would result in:

<span class='headline'> Hello World!</span>

So far so great. But you might have noticed the arguments in the original
string? I want to pass those! I would prefer to have them this way:

headline("Hello World", "color=#000000", "size=2");

And then extrat them with func_get_arg().
Why not pass an array containing the options?

$options = array();
$options[] = 'size="2"';
$options[] = 'color="#000000"';
headline('Hello World', $options);
But how do I translate a string to
seperated arguments for a function?


Use an XML/HTML parser to parse the input string,
isolate the options and add them to the array.

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.