3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ '%foo!bar', '@baz', '!bam@bat@bar', '%bee@baa', ]; $field = 'your_column'; $conditionTemplates = [ '&' => '%1$s = ?', '!' => '%1$s IS NULL OR %1$s != ?', '%' => '%1$s LIKE ?', '@' => '%1$s NOT LIKE ?', ]; $needsTrailingWildcard = ['%', '@']; foreach ($strings as $string) { $conditions = []; // reset for demo $params = []; // reset for demo preg_match_all('~([&%@!])([^&%@!]+)~', $string, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $conditions[] = sprintf($conditionTemplates[$match[1]], $field); $params[] = $match[2] . (in_array($match[1], $needsTrailingWildcard) ? '%' : ''); } var_export([implode(' AND ', $conditions), $params]); echo "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => 'your_column LIKE ? AND your_column IS NULL OR your_column != ?', 1 => array ( 0 => 'foo%', 1 => 'bar', ), ) array ( 0 => 'your_column NOT LIKE ?', 1 => array ( 0 => 'baz%', ), ) array ( 0 => 'your_column IS NULL OR your_column != ? AND your_column NOT LIKE ? AND your_column NOT LIKE ?', 1 => array ( 0 => 'bam', 1 => 'bat%', 2 => 'bar%', ), ) array ( 0 => 'your_column LIKE ? AND your_column NOT LIKE ?', 1 => array ( 0 => 'bee%', 1 => 'baa%', ), )

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:
54.08 ms | 402 KiB | 8 Q