Skip to content

Instantly share code, notes, and snippets.

@Jany-M
Last active June 6, 2021 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jany-M/4be37803d1dedd1113390dfcdad97c14 to your computer and use it in GitHub Desktop.
Save Jany-M/4be37803d1dedd1113390dfcdad97c14 to your computer and use it in GitHub Desktop.
[PHP] Common RegEx
<?php
// 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="http://somevideo.com/abc"]';
preg_match_all("\bmp4="(.+)\b", $text, $matches);
var_dump($matches[0]);
// http://somevideo.com/abc
$text = '[gravityform description="true" id="23" title="true"]';
preg_match_all("\bid="([0-9]+)\b", $text, $matches);
var_dump($matches[0]);
// 23
// Get Youtube ID from url
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video_url, $match);
var_dump($match[1]);
// XZ-Hr7Onr7k
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment