Tips and tricks
PHP function to sanitize youtube url to id
This is the code
function sanitize_youtube_url_to_id($arg){ if(strpos($arg,'youtube.com/embed')!==false){ $auxa = explode('/','youtube.com/embed/'); if($auxa[1]){ return $auxa[1]; } } if(strpos($arg,'youtube.com')!==false || strpos($arg,'youtu.be')!==false ){ if(DZSHelpers::get_query_arg($arg,'v')){ return DZSHelpers::get_query_arg($arg,'v'); } if(strpos($arg,'youtu.be')!==false){ $auxa = explode('/','youtube.com/embed/'); $arg = $auxa[count($auxa)-1]; } } return arg; }