3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <p>Zip Code: 99501</p> <p>Part Number: 67001</p> <p>Part Number: 98765 - 10000kg capacity</p> <p>Some dummy/interfering text. Part Number: 12345</p> <p>Zip Codes: 99501, 99524 , 85001 and 72201</p> <p>Part Number: 50545 &ndash; 450g Cartridge 50525 - 2.5kg Tub 50520 - 20kg Pail 50555 - 55kg Drum 50575 *Indent - 175kg Drum</p> HTML; $partnos = []; $dom = new DOMDocument; $dom->loadHTML($html); $xpath = new DOMXPath($dom); foreach ($xpath->query("//p[starts-with(., 'Part Number: ')]") as $node) { // echo "Qualifying text: {$node->nodeValue}\n"; if (preg_match_all('~\b\d{5}\b~', $node->nodeValue, $matches)) { $partnos = array_merge($partnos, $matches[0]); //or array_push($partnos, ...$matches[0]); } } var_export($partnos);
Output for git.master_jit, git.master, rfc.property-hooks
array ( 0 => '67001', 1 => '98765', 2 => '50545', 3 => '50525', 4 => '50520', 5 => '50555', 6 => '50575', )

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.94 ms | 405 KiB | 5 Q