dimanche 1 décembre 2019

How can I use PHP foreach in the following example?

I have a big issue right now in using php foreach function.

I need to return each name plus each value from the html source code below or a similar one. Example: {_pn_Brand:Dell}. Everything good so far.

My problem is that the source code contains one or more parameters (in my example below: _pn_Hardware Connectivity, _pn_Features) which can be found several times in the source code and I only need to return the checked ones.

To be more specific I need to return something like: {_pn_Hardware Connectivity:HDMI,USB 2.0}, {_pn_Features:Backlit Keyboard,Bluetooth,Built-in Microphone,Built-in Webcam}.

Please keep in mind that the attributes names like _pn_Hardware Connectivity or _pn_Features can change in other source codes so I need a foreach function to generally solve my problem.

I hope you guys understand exactly what I'm looking for. My apologise for the poor explanation but couldn't think of a better one for the moment. Please check the html source code below:

<input type="text" name="_pn_Brand" size="21" maxlength="50" gname="Brand" value="Dell">
<input type="text" name="_pn_MPN" size="21" maxlength="50" value="">
<input type="text" name="_pn_Type" size="21" maxlength="50" value="Notebook/Laptop">
<input type="text" name="_pn_Screen Size" size="21" maxlength="50" value="17 in">
<input type="text" name="_pn_RAM Size" size="21" maxlength="50" value="16 GB">
<input type="text" name="_pn_Processor" size="21" maxlength="50" value="Intel Core i7 4th Gen Quad core.">
<input type="text" name="_pn_Graphics Processing Type" size="21" maxlength="50" value="Dedicated Graphics">
<input type="text" name="_pn_Manufacturer Colour" size="21" maxlength="50" value="Black">
<input type="text" name="_pn_Manufacturer warranty" size="21" maxlength="50" value="None" closed="true">
<input type="text" name="_pn_Processor Speed" size="21" maxlength="50" value="2.50- 3.20 GHz">
<input type="text" name="_pn_pnorage Type" size="21" maxlength="50" value="HDD (Hard Disk Drive)">
<input type="text" name="_pn_Hard Drive Capacity" size="21" maxlength="50" value="500 GB">
<input type="text" name="_pn_Operating System" size="21" maxlength="50" value="Windows 10">
<input type="text" name="_pn_Operating System Edition" size="21" maxlength="50" value="Professional">
<input type="text" name="_pn_Release Year" size="21" maxlength="50" value="2014">
<input type="text" name="_pn_Colour" size="21" maxlength="50" value="Black">
<input type="checkbox" name="_pn_Hardware Connectivity" value="DisplayPort">
<input type="checkbox" name="_pn_Hardware Connectivity" value="Mini DisplayPort">
<input type="checkbox" name="_pn_Hardware Connectivity" value="HDMI" checked="checked">
<input type="checkbox" name="_pn_Hardware Connectivity" value="Micro-HDMI">
<input type="checkbox" name="_pn_Hardware Connectivity" value="Micro-USB">
<input type="checkbox" name="_pn_Hardware Connectivity" value="Mini-USB">
<input type="checkbox" name="_pn_Hardware Connectivity" value="USB 1.0/1.1">
<input type="checkbox" name="_pn_Hardware Connectivity" value="USB 2.0" checked="checked">
<input type="checkbox" name="_pn_Hardware Connectivity" value="USB 3.0">
<input type="checkbox" name="_pn_Hardware Connectivity" value="USB 3.1">
<input type="checkbox" name="_pn_Features" value="10/100 LAN Card">
<input type="checkbox" name="_pn_Features" value="3D Camera">
<input type="checkbox" name="_pn_Features" value="Backlit Keyboard" checked="checked">
<input type="checkbox" name="_pn_Features" value="Bluetooth" checked="checked">
<input type="checkbox" name="_pn_Features" value="Built-in Microphone" checked="checked">
<input type="checkbox" name="_pn_Features" value="Built-in Webcam" checked="checked">
<input type="checkbox" name="_pn_Features" value="HSDPA">
<input type="checkbox" name="_pn_Features" value="Tablet PC">
<input type="checkbox" name="_pn_Features" value="Touchscreen">
<input type="checkbox" name="_pn_Features" value="Virtual Reality Ready">

Thanks to everyone that can help in advance!




Aucun commentaire:

Enregistrer un commentaire