开发者

Make the value of a select box the same as the name of the option without copy paste

my question is how can I replace all the values with the option name without copy paste. The new list will be happen once, so that it can help me to win hours of copy-paste.

It's been a puzzle to me. Thanks for your solutions and ideas.

<option value="61">Talbot</option>
<option value="3830">Tata</option>
<option value="248">开发者_运维技巧Toyota</option>
<option value="63">Trabant</option>
<option value="64">Triumph</option>
<option value="651">Uaz</option>

This is an example of what I want

<option value="Talbot">Talbot</option>


If you want to do this with PHP you should use preg_replace() function It will look something like this:

<?php
$ptn    = "/<option value=\"(.*)\">(.*)<\/option>/";
$str    = '<option value="61">Talbot</option>';
$rpltxt = '<option value="$2">$1</option>';
echo preg_replace($ptn, $rpltxt, $str);
?>

output will be:

<option value="Talbot">61</option>


because most people do interesting things with whitespace, case, and quotes, there are few guarantees.

a proper search regex would look like

"/<[oO][pP][tT][iI][oO][nN]\s+[vV][aA][lL][uU][eE]\s*=\s*['\"]?(.*)['\"]?\s*>(.*)</[oO][pP][tT][iI][oO][nN]>/"

replace with "<option value=\"$2\">$2</option>"

the first set of perens are not required (but the .* is).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜