3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "ayy lmao tag: anal, dick pornstar: James Deen channel:x-Art" . " end:"; $pattern = "/.+?(?=(tag|pornstar|channel|end)+:)/"; preg_match_all($pattern, $string, $matches); $meme = array(); $final = array(); for($i = 0; $i < sizeof($matches[0]); $i++) { $meme[$i] = explode(":", $matches[0][$i]); } $sql = "SELECT "; for($i = 0; $i < sizeof($meme); $i++) { if(sizeof($meme[$i]) == 1) { $sql .= "`videos`.`name`"; } else { $sql .= "`" . $meme[$i][0] . "s`.`name`"; } if($i != sizeof($meme)-1) { $sql .= ", "; } } $sql .= "\nFROM `videos`\n"; for($i = 0; $i < sizeof($meme); $i++) { if(sizeof($meme[$i]) == 2) { $sql .= "LEFT JOIN `video_" . $meme[$i][0] . "s` ON `video_" . $meme[$i][0] . "s`.`video` = `videos`.`id`\n"; $sql .= "LEFT JOIN `" . $meme[$i][0] . "s` ON `" . $meme[$i][0] . "s`.`id` = `video_`" . $meme[$i][0] . "s`.`" . $meme[$i][0] . "`\n"; } } $sql .= "\nWHERE\n"; for($i = 0; $i < sizeof($meme); $i++) { if(sizeof($meme[$i]) == 1) { $sql .= "`videos`.`name` LIKE '% " . $meme[$i][1] . "%'\n"; } else { $sql .= "`" . $meme[$i][0] . "`.`name` LIKE '%" . $meme[$i][1] . "%'\n"; } if($i != sizeof($meme)-1) { $sql .= "\nAND\n"; } } print_r($matches); print_r($meme); print_r($sql); ?>
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined array key 1 in /in/RBCaF on line 41 Array ( [0] => Array ( [0] => ayy lmao [1] => tag: anal, dick [2] => pornstar: James Deen [3] => channel:x-Art ) [1] => Array ( [0] => tag [1] => pornstar [2] => channel [3] => end ) ) Array ( [0] => Array ( [0] => ayy lmao ) [1] => Array ( [0] => tag [1] => anal, dick ) [2] => Array ( [0] => pornstar [1] => James Deen ) [3] => Array ( [0] => channel [1] => x-Art ) ) SELECT `videos`.`name`, `tags`.`name`, `pornstars`.`name`, `channels`.`name` FROM `videos` LEFT JOIN `video_tags` ON `video_tags`.`video` = `videos`.`id` LEFT JOIN `tags` ON `tags`.`id` = `video_`tags`.`tag` LEFT JOIN `video_pornstars` ON `video_pornstars`.`video` = `videos`.`id` LEFT JOIN `pornstars` ON `pornstars`.`id` = `video_`pornstars`.`pornstar` LEFT JOIN `video_channels` ON `video_channels`.`video` = `videos`.`id` LEFT JOIN `channels` ON `channels`.`id` = `video_`channels`.`channel` WHERE `videos`.`name` LIKE '% %' AND `tag`.`name` LIKE '% anal, dick %' AND `pornstar`.`name` LIKE '% James Deen %' AND `channel`.`name` LIKE '%x-Art %'

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:
59.44 ms | 404 KiB | 8 Q