Last active
June 6, 2021 16:23
-
-
Save Jany-M/4be37803d1dedd1113390dfcdad97c14 to your computer and use it in GitHub Desktop.
[PHP] Common RegEx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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