473,320 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

translate string to function arguments

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
1 1871
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bengt Richter | last post by:
Just thought None as the first argument would be both handy and mnemonic, signifying no translation, but allowing easy expression of deleting characters, e.g., s = s.translate(None,...
1
by: Joe | last post by:
Hi all Is there a TSQL function like Oracle's Translate function? Where: Translate('13,000 Miles','abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ, ',' ') would return '13000'? I'm...
35
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your...
1
by: kennethfine | last post by:
I'm transitioning from ASP development, please excuse these basic questions. One thing I did often in ASP was create a "translate" function to render one string to another, strip out excess...
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
6
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
3
by: Mehmet Baserdem | last post by:
Hi all, I am trying to remove all blank chars in middle of the string "text1 text2 text3 text3 text4" with following stmt: VALUES(translate('text1 text2 text3 text3 text4' ...
3
by: amija0311 | last post by:
Hi, I am new using DB2 9.1 database by windows base. I want to query the data that contain string then translate the string into integer using DB2. The problems is If the data is null, i got the...
4
by: kovariadam | last post by:
Hi, Does anybody know why i get this error: SQL0176N The second, third or fourth argument of the TRANSLATE scalar function is incorrect. SQLSTATE=42815 with this query: SELECT...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.