Connecting Tech Pros Worldwide Forums | Help | Site Map

regs?

Yang Li Ke
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi Guys!

I need a way to convert a string like this:

<select name="something">
<option value="1">var1</option>
<option value="2">var2</option>
<option value="3">var3</option>
<option value="4">var4</option>
</select>

to this:

something=[1,2,3,4]

Anyone can help?
--
Yang



Pedro Graca
Guest
 
Posts: n/a
#2: Jul 17 '05

re: regs?


Yang Li Ke wrote:[color=blue]
> Hi Guys!
>
> I need a way to convert a string like this:
>[/color]


<?php
$str = <<<STR[color=blue]
> <select name="something">
> <option value="1">var1</option>
> <option value="2">var2</option>
> <option value="3">var3</option>
> <option value="4">var4</option>
> </select>[/color]
STR;

[color=blue]
>
> to this:
>
> something=[1,2,3,4][/color]


$str2 = preg_replace('@<select name="(\w*)">.*@s', '$1=[', $str);
preg_match_all('@<option value="(\d)">var\d</option>@', $str, $values);
$str2 .= implode(',', $values[1]) . ']';
?>


--
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 :
Closed Thread