Forum Moderators: coopster

Message Too Old, No Replies

Pass data from special tags to a variable

         

Imaster

11:42 am on Mar 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

I want to pick up values for variables from special tags that I have created. For eg:

$name variable should pick up the data which exists between the following special tag I have created : <name>John</name>

So $name = John.

In short, this variable will look for the opening and closing tags <name></name> and use whatever data exists between them as its data.

I am a novice at php and I might have used confusing words above.

Any inputs would be appreciated.

Habtom

12:18 pm on Mar 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might try to explode them. May be twice once to get the data between the tags and again for the variable between <>.

I hope this works.

Habtom

HoagieKat

12:23 pm on Mar 28, 2006 (gmt 0)

10+ Year Member



You could use a regular expression to detect the presence of the tags.

something like

preg_match_all("\<.\>[.]+\<\/\>",$input,$matches);

will put everything that matches <*>*</*> into an array called $matches (I think! I'm not that good with regular expressions)

or

preg_match_all("\<name\>[.]+\<\/name\>",$input,$matches);

should match <name>anything</name> (again, I think!)

If you do a search on google for Perl Regular Expressions or RegEx Library you'll find lots of sites explaining them.