3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** Some strings to test our code */ $testStrings=[ "adress=example.com port=464", "adress =example.com\nport=4645", "port=1 protocol=https adress= example.com", ]; /** Test for each string */ foreach($testStrings as $string) { print "\n\nTESTING:'".escapeshellarg($string)."'\n"; /** First method - does not match them all */ if(preg_match('/\badress=([a-z\.]*)\s+port=(\d*)/',$string,$matches)) { print "Matched {$matches[1]}:{$matches[2]}\n"; } /** Second method - get param/value pairs first, then check them */ if(preg_match_all('/\b(?P<param>[^\d\s]\S*)\s*=\s*(?P<value>\S*)(?:\s|$)/m',$string,$matches)) { //var_dump($matches); // Uncomment to see the raw data. $i=0; // We need an index. foreach($matches['param'] as $param) { $value=$matches['value'][$i]; // Put value in local $value $i++; switch($param) { // Find parameters we know, complain if needed. case "adress": print "ADDRESS IS $value\n"; break; case "port": if(($result=preg_match('/^\d{3}$/',$value))) { var_dump($result); print "PORT IS $value\n"; } else { print "PORT MUST HAVE EXACTLY 3 DIGITS - Got: $value\n"; } break; default: print "UNKNOWN PARAMETER $param=$value\n"; } } } }
Output for git.master, git.master_jit, rfc.property-hooks
TESTING:''adress=example.com port=464'' Matched example.com:464 ADDRESS IS example.com int(1) PORT IS 464 TESTING:''adress =example.com port=4645'' ADDRESS IS example.com PORT MUST HAVE EXACTLY 3 DIGITS - Got: 4645 TESTING:''port=1 protocol=https adress= example.com'' PORT MUST HAVE EXACTLY 3 DIGITS - Got: 1 UNKNOWN PARAMETER protocol=https ADDRESS IS example.com

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:
155.56 ms | 406 KiB | 5 Q