3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isQuotedString($token) { return in_array($token[0], array('"', "'")) && $token[0] == $token[strlen($token) - 1]; } function getQueryTokens($query) { static $expr = '/("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')/'; $tokens = []; foreach (preg_split($expr, $query, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $token) { if (isQuotedString($token)) { $tokens[] = $token; } else { $tokens = array_merge($tokens, preg_split('/(\?)/', $token, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)); } } return $tokens; } var_dump(getQueryTokens("SELECT * FROM foo WHERE 'a' = b AND f = ? AND q IN (?)"));
Output for git.master, git.master_jit, rfc.property-hooks
array(7) { [0]=> string(24) "SELECT * FROM foo WHERE " [1]=> string(3) "'a'" [2]=> string(13) " = b AND f = " [3]=> string(1) "?" [4]=> string(11) " AND q IN (" [5]=> string(1) "?" [6]=> string(1) ")" }

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:
39.13 ms | 401 KiB | 8 Q