3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Ingreso $html = ' <img class="img" src="ejemplo1.jpg"> <img width="72" height="72" alt="" class="bo img" src="https://scontent-mia3-2.xx.fbcdn.net/v/t1.0-1/cp0/e15/q65/p74x74/21151613_1725782907724134_7535903357386699205_n.jpg?efg=eyJpIjoiYiJ9&amp;oh=4f22a577f965566b2016ef842f5b110f&amp;oe=5A1DE043"> <img class="bo etc" src="ejemplo2.jpg"> <img class="bo etc img" src="ejemplo3.jpg"> '; //Englobamos en body para corregirlo y que lo procese bien $html = "<body>$html</body>"; //Generar el DOM $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NOIMPLIED | LIBXML_NONET | LIBXML_HTML_NODEFDTD); //Obtener todas las imágenes $img_nodelist = $dom->getElementsByTagName('img'); //Recorrer cada una foreach ($img_nodelist as $img) { //Obtener la lista de clases $clases = $img->getAttribute('class'); $clases_arr = explode(' ', $clases); //Ver si contiene ambas clases $clases_buscadas = array('bo', 'img'); if (!array_diff($clases_buscadas, $clases_arr)) { //Contiene las clases //Obtener el SRC $urlImagen = $img->getAttribute('src'); echo "URL: $urlImagen\n"; } }
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
URL: https://scontent-mia3-2.xx.fbcdn.net/v/t1.0-1/cp0/e15/q65/p74x74/21151613_1725782907724134_7535903357386699205_n.jpg?efg=eyJpIjoiYiJ9&oh=4f22a577f965566b2016ef842f5b110f&oe=5A1DE043 URL: ejemplo3.jpg
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Notice: Use of undefined constant LIBXML_HTML_NOIMPLIED - assumed 'LIBXML_HTML_NOIMPLIED' in /in/OYNce on line 17 Notice: Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD' in /in/OYNce on line 17 Warning: DOMDocument::loadHTML() expects exactly 1 parameter, 2 given in /in/OYNce on line 17
Output for 5.0.0 - 5.0.5
Notice: Use of undefined constant LIBXML_COMPACT - assumed 'LIBXML_COMPACT' in /in/OYNce on line 17 Notice: Use of undefined constant LIBXML_HTML_NOIMPLIED - assumed 'LIBXML_HTML_NOIMPLIED' in /in/OYNce on line 17 Notice: Use of undefined constant LIBXML_NONET - assumed 'LIBXML_NONET' in /in/OYNce on line 17 Notice: Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD' in /in/OYNce on line 17 Warning: DOMDocument::loadHTML() expects exactly 1 parameter, 2 given in /in/OYNce on line 17
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/OYNce on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/OYNce on line 16

preferences:
207.33 ms | 412 KiB | 5 Q