vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Parse URL (https://vborg.vbsupport.ru/showthread.php?t=139155)

s0b 02-12-2007 06:48 AM

Parse URL
 
Hi all, im using the anymedia plugin and under all videos I include the original URL to the video.


That i want is that url dont appear like this:

http://www .youtube.com/watch?v=AOEpkt7RZy0 (without spaces)

I want that it parse the name of the video (or the title of the web)

carlitos - el baile de la ducha (or YouTube - carlitos - el baile de la ducha).

Very much thanks

Ducks 02-12-2007 10:03 AM

This will get the title from that page:

Quote:

<?php
$url = 'http://www.youtube.com/watch?v=AOEpkt7RZy0';

$src = file_get_contents($url);
echo substr($src, strrpos($src, '<title>') + 7, strrpos($src, '</title>') - strrpos($src, '<title>'));
?>

s0b 02-12-2007 10:34 AM

Great! very much thanks Duck!! that code i will insert it in the template or in the php?

Ducks 02-12-2007 10:38 AM

Sorry I'm not able to give you that answer, but due performance issues you should grab the title when the link is posted and not everytime it's viewed as it would slow down your site a lot.

Analogpoint 02-12-2007 04:30 PM

What you'd have to do is create a plugin that pulls the title from YouTube and saves it to the database, to then be displayed each time the page is loaded.

@Ducks:

echo substr($src, strrpos($src, '<title>') + 7, strrpos($src, '</title>') - strrpos($src, '<title>'));

You could you preg_match as an alternative to this. If you want to use the code you've written, stripos would be better because it's case-insensitive. BTW, why would you want to search starting at the end of the HTML document?

Code:

preg_match('%<title>([^<]+)<\/title>%i', file_get_contents ($url), $matches);
$title = $matches[1];



All times are GMT. The time now is 09:04 PM.

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.00963 seconds
  • Memory Usage 1,719KB
  • 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_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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