3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input_lines = 'This is a test for<img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Girl">my <img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Girl">regex which<img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Girl">should be alright <img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Not-Talking">and<img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Not-Talking"> match all this emoticons except things like <img dsopjfdojp <img oew> because this ones are not real emoticons! The following is a real one: <img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Girl">'; $doc = new DOMDocument(); // Suppress warnings @$doc->loadHTML($input_lines); $imgs = $doc->getElementsByTagName("img"); $number_of_imgs = $imgs->length; echo "Found $number_of_imgs images" . PHP_EOL; // The plain text is actually the nodeValue of // the whole snippet. $text = $imgs->item(0)->parentNode->nodeValue; $len = mb_strlen($text); echo "Text length: $len + $number_of_imgs(images)" . PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
Found 7 images Text length: 170 + 7(images)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
154.81 ms | 405 KiB | 5 Q