I have a huge number of records in a drop-down box(approximately 27000 or more).
HTML -
<select name="manufacturer" id="manufacturer">
<option value="">Select a Builder</option>
<option value="1-hull">#1 Hull</option>
<option value="49er">49er</option>
<option value="a-m-f">A M F</option>
<option value="a-m-manufacturing">A&M Manufacturing</option>
<option value="a1-custom-trailers">A1 Custom Trailers</option>
- - - - - -
- - - - - -
<option value="zuma">Zuma</option>
</select>
Above drop-down I collect this data from different website. I want to put in my own website with dynamic content. I have tried to insert one by one it is not possible to insert all record in single handed. So I want to any shortcut method for insert all these text in my MySQL
database table. I need option inner HTML text will inserting into my database table.
If I will get all the option text in an Array
then easily I can manage it. But I am confused how to get all text in Array
by using PHP
code.
Here's a solution with preg_match_all
<?php
$string = '<option value="">Select a Builder</option>
<option value="1-hull">#1 Hull</option>
<option value="49er">49er</option>
<option value="a-m-f">A M F</option>
<option value="a-m-manufacturing">A&M Manufacturing</option>
<option value="a1-custom-trailers">A1 Custom Trailers</option>
<option value="zuma">Zuma</option>
';
preg_match_all('/>(.*?)<\//',$string,$matches);
var_dump($matches[1]);
?>
DOM Document
is your buddy,
$str = '<select name="manufacturer" id="manufacturer">
<option value="">Select a Builder</option>
<option value="1-hull">#1 Hull</option>
<option value="49er">49er</option>
<option value="a-m-f">A M F</option>
<option value="a-m-manufacturing">A&M Manufacturing</option>
<option value="a1-custom-trailers">A1 Custom Trailers</option>
<option value="zuma">Zuma</option>
</select>';
$doc = new DOMDocument();
$doc->loadHTML($str);
$options = $doc->getElementsByTagName('option');
foreach ($options as $option) {
$value[] = $option->nodeValue;
}
$value; // will contain array with all option values