Skip to content

Instantly share code, notes, and snippets.

@Jany-M Jany-M/php_regex.php
Last active Oct 10, 2018

What would you like to do?
[PHP] Common RegEx
// Let's be honest, RegEx is not fun, so these may come in handy
// I'll update this in case I write/find more
$text = '[video mp4=""]';
preg_match_all("\bmp4="(.+)\b", $text, $matches);
$text = '[gravityform description="true" id="23" title="true"]';
preg_match_all("\bid="([0-9]+)\b", $text, $matches);
// 23
// Get Youtube ID from url
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video_url, $match);
// XZ-Hr7Onr7k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.