开发者

Isolate dropdown box text with PHP

开发者 https://www.devze.com 2022-12-17 05:48 出处:网络
How could I isolate just the text from this dropdown box code into a comma separated list (i.e. the first few would be: 375515,Adeks Op console,Ambassador Extensions):

How could I isolate just the text from this dropdown box code into a comma separated list (i.e. the first few would be: 375515,Adeks Op console,Ambassador Extensions):

<option value="667">375515</option>
                        <option value="606">Adeks Op console</option>
                        <option value="607">Ambassador Extensions</option>
                        <option value="608">Calypso 1100</option>

                        <option value="609">Calypso 225</option>
                        <option value="1681">Companion</option>
                        <option value="612">Converse 100</option>
                        <option value="621">Converse 1100</option>
                        <option value="613">Converse 120</option>
                        <option value="618">Converse 1200</option>

                        <option value="619">Converse 1300</option>
                        <option value="620">Converse 1400</option>
                        <option value="614">Converse 180</option>
                        <option value="610">Converse 200</option>
                        <option value="615">Converse 2015</option>
                        <option value="616">Converse 2025</option>

                        <option value="622">Converse 220</option>
                        <option value="623">Converse 225</option>
                        <option value="611">Converse 300</option>
                        <option value="624">Converse 320</option>
                        <option value="625">Converse 325</option>
                        <option value="626">Converse 420</option>

                        <option value="627">Converse 425</option>
                        <option value="628">Decor 100</option>
                        <option value="632">Decor 110</option>
                        <option value="629">Decor 200</option>
                        <option value="633">Decor 210</option>
                        <option value="630">Decor 300</option>

                        <option value="631">Decor 400</option>
                        <option value="634">Diverse 2016</option>
                        <option value="2273">Diverse 3010 Micro</option>
                        <option value="2270">Diverse 3016</option>
                        <option value="635">Diverse 4010 Classic</option>
                        <option value="637">Diverse 4010 Executive</option>

                        <option value="636">Diverse 4016 Classic</option>
                        <option value="638">Diverse 4016 Executive</option>
                        <option value="2285">Diverse 5110</option>
                        <option value="2316">Diverse 5210</option>
                        <option value="2314">Diverse 5300</option>
                        <option value="2317">Diverse 5310</option>

                        <option value="2312">Diverse 5350</option>
                        <option value="2318">Diverse 5410</option>
                        <option value="2313">Diverse 5450</option>
                        <option value="639">Diverse 6210</option>
                        <option value="640">Diverse 6250</option>
                        <option value="641">Diverse 6410</option>

                        <option value="642">Diverse 6450</option>
                        <option value="734">Diverse X10</option>
                        <option value="735">Diverse X5</option>
                        <option value="643">Duet 200</option>
                        <option value="644">Elements</option>
                        <option value="646">Equinox 1200</option>

                        <option value="647">Equinox 1350</option>
                        <option value="645">Esprit 1250</option>
                        <option value="648">Featureline Featurephone</option>
                        <option value="1686">Featurenet</option>
                        <option value="649">Freelance XD500</option>
                        <option value="650">Freestyle 2010</option>

                        <option value="652">Freestyle 210</option>
                        <option value="711">Freestyle 2100</option>
                        <option value="653">Freestyle 250</option>
                        <option value="651">Freestyle 310</option>
                        <option value="1123">Freestyle 310</option>
                        <option value="654">Freestyle 3200</option>

                        <option value="656">Freestyle 350</option>
                        <option value="655">Freestyle 3500</option>
                        <option value="658">Freestyle 4100</option>
                        <option value="657">Freestyle 610</option>
                        <option value="723">Freestyle 6100</option>
                        <option value="712">Freestyle XD100</option>

                        <option value="659">Glide</option>
                        <option value="660">Herald Op Console</option>
                        <option value="661">Innovator Extensions</option>
                        <option value="662">Inspiration</option>
                        <option value="663">ITS</option>
                        <option value="664">Kinsman Op Console</option>

                        <option value="665">M1250</option>
                        <option value="1729">M2216</option>
                        <option value="1732">M2216D</option>
                        <option value="1742">M2250</option>
                        <option value="1725">M2616</option>
                        <option value="1745">M3110</option>

                        <option value="1747">M3310</option>
                        <option value="1751">M3820</option>
                        <option value="1757">M3901</option>
                        <option value="1760">M3902</option>
                        <option value="1763">M3903</option>
                        <option value="1762">M3904</option>

                        <option value="1775">M3905</option>
                        <option value="1780">M5212</option>
                        <option value="666">M5312</option>
                        <option value="1806">M6310</option>
                        <option value="1807">M6320</option>
                        <option value="1840">M7100</option>

                        <option value="1814">M7324</option>
                        <option value="724">Mango</option>
                        <option value="669">Marquis Extensions</option>
                        <option value="670">Merlin All Extensions</option>
                        <option value="671">Merlin Op Console</option>
                        <option value="672">Modular</option>

                        <option value="673">Monarch Op Console</option>
                        <option value="674">Navigator</option>
                        <option value="675">Octara</option>
                        <option value="679">On-Air 1100</option>
                        <option value="680">On-Air 1300</option>
                        <option value="683">On-Air 1800 Classic</option>

                        <option value="684">On-air 2000 Classic</option>
                        <option value="685">On-Air 2000 Executive</option>
                        <option value="686">On-air 2100 Classic</option>
                        <option value="687">On-Air 2100 SMS</option>
                        <option value="688">On-air 2250 Classic</option>
                        <option value="689">Paragon 200</option>

                        <option value="690">Paragon 400</option>
                        <option value="692">Paragon 450</option>
                        <option value="691">Paragon 500</option>
                        <option开发者_高级运维 value="693">Paragon 550</option>
                        <option value="694">Paragon 650</option>
                        <option value="695">Pathway Console</option>

                        <option value="696">Pentara</option>
                        <option value="697">Regent Op Console</option>
                        <option value="698">Relate 100</option>
                        <option value="700">Relate 1500</option>
                        <option value="699">Relate 250</option>
                        <option value="617">Relate 3000</option>

                        <option value="701">Relate 550</option>
                        <option value="702">Relate 600</option>
                        <option value="703">Relate 700</option>
                        <option value="704">Relate 80</option>
                        <option value="705">Response</option>
                        <option value="722">Reveal</option>

                        <option value="706">Revelation Extensions</option>
                        <option value="668">S6022</option>
                        <option value="707">Senator Extension</option>
                        <option value="708">Senator Op Console</option>
                        <option value="710">Studio</option>
                        <option value="713">Synergy 1000</option>

                        <option value="714">Synergy 2150</option>
                        <option value="715">Synergy 3100</option>
                        <option value="716">Synergy 3105</option>
                        <option value="717">Synergy 3200 SMS</option>
                        <option value="718">Synergy 3205</option>
                        <option value="719">Synergy 3500</option>

                        <option value="720">Synergy 3505</option>
                        <option value="721">Synergy 4100</option>
                        <option value="725">Synergy 4500</option>
                        <option value="1841">T7100</option>
                        <option value="1855">T7208</option>
                        <option value="1850">T7316</option>

                        <option value="729">TSX50 Op Console</option>
                        <option value="728">TXS50 Extensions</option>
                        <option value="730">Vanguard Extensions</option>
                        <option value="732">Versatility V16 Featurephone</option>
                        <option value="733">Versatility V8 Featurephone</option>
                        <option value="736">Verve 3010 Exceutive</option>

                        <option value="2992">Verve 450</option>
                        <option value="737">Viceroy Extensions</option>

Thanks, B.


You can use DOMDocument to accomplish this fairly easily. loadHTML($string) or loadHTMLFile($fileName) can be used to read in the HTML depending on whether you have it in a file or a string, then you can do this:

$doc = new DOMDocument();
$doc->loadHTMLFile('test.html');
$nodes = $doc->getElementsByTagName('option');
$optionVals = array();
foreach($nodes as $o) {
    $optionVals[] = $o->nodeValue;
}
echo implode(',',$optionVals);


Is this what you want? This is pseudo-code to be edited into PHP by someone that actually knows that language:

data = "375515,Adeks Op console,Ambassador Extensions...";

i = 0;
foreach(item in data.split(",")) {
    printf("<option value=\"\s\">\s</option>\n", i, item);
    i++;
}
0

精彩评论

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

关注公众号