3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strLimit = explode(',',"rpt_Job_Tracking,rpt_Customer_Routing_Report"); $str ="<optgroup label='Billing Summary Reports' style='color:blue;font-weight:bold;'> <option style='color:black; font-weight:normal' value='JobTracking'>Job Tracking</option> <option style='color:black; font-weight:normal' value='CustomerRouting' selected>Customer Routing Report</option> <option style='color:black; font-weight:normal' value='BillingStatistics'>Billing Statistics</option> <option style='color:black; font-weight:normal' value='BranchReport'>Branch Report</option> <option style='color:black; font-weight:normal' value='BranchBilling'>Branch Billing Report</option> <option style='color:black; font-weight:normal' value='BillingActivityDetail'>Billing Activity Details</option> </optgroup> <optgroup label='e-Adoption Reports' style='color:blue;font-weight:bold;'> <option style='color:black; font-weight:normal' value='eAdoptionDashboard'>e-Adoption Dashboard</option> <option style='color:black; font-weight:normal' value='eAdoptionReport'>e-Adoption Chart</option> <option style='color:black; font-weight:normal' value='TopBillingCusts'>Top Paper Customers</option> <option style='color:black; font-weight:normal' value='TopBillingCustsAcctNum'>Top Paper Custs by Acct Num</option> <option style='color:black; font-weight:normal' value='BranchEBillReport'>Branch Electronic Report</option> <option style='color:black; font-weight:normal' value='EasyImportUsage'>EasyImport Usage</option> </optgroup> <optgroup label='eBilling and ePayment' style='color:blue;font-weight:bold;'> <option style='color:black; font-weight:normal' value='OnlinePayments'>Online Payments</option> <option style='color:black; font-weight:normal' value='PaymentFile'>Payment File Report</option> <option style='color:black; font-weight:normal' value='ACHTransfers'>ACH Transfers</option> <option style='color:black; font-weight:normal' value='IGUsage'>Invoice Gateway Usage Report</option> <option style='color:black; font-weight:normal' value='ObpAccountAudit'>Online Account Audit Report</option> <option style='color:black; font-weight:normal' value='EUsageReport'>Invoice Central Usage Report</option> <option style='color:black; font-weight:normal' value='IGUsers'>Online User Report</option> <option style='color:black; font-weight:normal' value='eDSOReport'>eDSO By Month</option> <option style='color:black; font-weight:normal' value='AutoPay'>Auto Pay Report</option> </optgroup> <optgroup label='Bullpen Reports' style='color:blue;font-weight:bold;'> <option style='color:black; font-weight:normal' value='BPInvoices'>Bullpenned Invoices</option> <option style='color:black; font-weight:normal' value='BPStatistics'>Bullpen Statistics</option> </optgroup> <optgroup label='Address Reports' style='color:blue;font-weight:bold;'> <option style='color:black; font-weight:normal' value='UncertifiedAddresses'>Uncertified Addresses</option> <option style='color:black; font-weight:normal' value='NCOAAddressesReport'>NCOA Addresses</option> </optgroup> <optgroup label='Miscellaneous' style='color:blue;font-weight:bold;'> <option style='color:black; font-weight:normal' value='InvoiceExtract'>Invoice Extract</option> <option style='color:black; font-weight:normal' value='FaxFailures'>Fax Failures</option> <option style='color:black; font-weight:normal' value='EmailFailures'>Transmittal Failures</option>"; $newStrItem = $newList = array(); foreach($strLimit as $strItem){ $strItem = str_replace('_', ' ', $strItem); $strItem = str_replace('rpt ', '', $strItem); $newStrItem[] = $strItem; } $rptList = array(); $doc = new DOMDocument(); $doc->loadHTML($str); $headings = $doc->getElementsByTagName('optgroup'); foreach($headings as $heading) { $parentItem = $heading->getAttribute('label'); if($heading->hasChildNodes()) { $childItems = $heading->getElementsByTagName('option'); foreach ($childItems as $childItem) { $rptList[$parentItem][] = $childItem->nodeValue; } } } foreach($rptList as $listKey=> $listVal) { $newArray[$listKey] = array_intersect($newStrItem, $listVal); } $newList = array_filter($newArray); $dom = new DOMDocument(); $dom->preserveWhiteSpace = false; $dom->loadHTML($str); $headings = $doc->getElementsByTagName('optgroup'); foreach($newList as $arrKey => $arrVal){ if($arrKey != $heading->getAttribute('label')){ $dom->parentNode->removeChild($headings); } } echo $dom->saveHTML(); //print_r($newList);
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Uncaught Error: Call to a member function removeChild() on null in /in/RpMWt:80 Stack trace: #0 {main} thrown in /in/RpMWt on line 80
Process exited with code 255.
Output for 5.6.0 - 5.6.38
Fatal error: Call to a member function removeChild() on null in /in/RpMWt on line 80
Process exited with code 255.
Output for 5.5.0 - 5.5.38
Fatal error: Call to a member function removeChild() on a non-object in /in/RpMWt on line 80
Process exited with code 255.

preferences:
227.61 ms | 401 KiB | 318 Q