vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Youtube RegExp Compatible with preg_match_all (https://vborg.vbsupport.ru/showthread.php?t=322672)

GHRake 05-18-2016 10:49 PM

Youtube RegExp Compatible with preg_match_all
 
Hello people of vbulletin, I've decided it's time to learn some php and write a vbulletin plugin.

So far so good:
https://images-1.discordapp.net/eyJ1...4R9i81gcAI.png

But I'm having trouble with getting a rexexp to work with preg_match_all()
I'm getting the dreaded
Quote:

"PHP Warning: preg_match_all(): Delimiter must not be alphanumeric or backslash"
When I use:
Code:

if (stripos($string, 'youtu') !== false)
{
$regex = 'https?:\/\/((.+\.youtube\.com\/watch\?v=)|(youtu\.be\/))([a-zA-Z0-9-_]+)';
preg_match_all($regex, $string, $matches);
if (!empty($matches))
{
    $og_array['og:video'] = $matches[2][0];
}
}

Any words of wisdom? TIA

cellarius 05-19-2016 04:35 AM

Just as the error states: You don't have any valid delimiters for your expression in $regex. Try:

PHP Code:

$regex "/https?:\/\/((.+\.youtube\.com\/watch\?v=)|(youtu\.be\/))([a-zA-Z0-9-_]+)/"


Paul M 05-19-2016 07:52 AM

As well as /, vbulletin uses # as the delimiter as well.

GHRake 05-19-2016 03:21 PM

Ah yes, thank you gentleman for your assistance


All times are GMT. The time now is 01:02 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00962 seconds
  • Memory Usage 1,714KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete