Author Topic: replace youtube url - bbcode - includes.php  (Read 5429 times)

0 Members and 1 Guest are viewing this topic.

Offline Sunny C.

  • Addicted member
  • ******
  • Posts: 1.806
  • I ♥ 4I
    • View Profile
replace youtube url - bbcode - includes.php
« on: October 27, 2010, 03:40:11 PM »
Hi,

I would like to know how the url from youtube-videos into the correct spelling can rewrite for the embed codes?

From: http://www.youtube.com/watch?v=HchX2bQnz3k
To: http://www.youtube.com/v/HchX2bQnz3k?fs=1&hl=de_DE&rel=0

I have created some other BBcodes, but here I need an example.

includes.php
    $search_array = array(
      
"/(\[)(youtube)(=)(['\"]?)(www\.youtube)([^\"']*)(\\4])(.*)(\[\/youtube\])/siU",
      
"/(\[)(youtube)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/youtube\])/siU",
      
"/(\[)(youtube)(])(www\.)([^\"]*)(\[\/youtube\])/siU",
      
"/(\[)(youtube)(])([^\"]*)(\[\/youtube\])/siU"
    
);
    
$replace_array = array(
      
"<a href=\"http://www.\\6\" target=\"_blank\" rel=\"nofollow\">\\8</a>",
      
"<a href=\"\\5\" target=\"_blank\" rel=\"nofollow\">\\7</a>",
      
"<a href=\"http://www.\\5\" target=\"_blank\" rel=\"nofollow\">www.\\5</a>",
      
"<object width=\"150\" height=\"150\"><param name=\"movie\" value=\"\\4\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"\\4\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"150\" height=\"150\"></embed></object>"
    
);


---

Hallo,

ich würde gerne wissen wie ich die url von youtube-videos in die richtige schreibweise für die embed-codes umschreiben kann?

Von: http://www.youtube.com/watch?v=HchX2bQnz3k
Zu: http://www.youtube.com/v/HchX2bQnz3k?fs=1&amp;hl=de_DE&amp;rel=0

Ich habe mir einige andere BBcodes erstellt, aber hier brauche ich ein Beispiel.

includes.php
    $search_array = array(
      
"/(\[)(youtube)(=)(['\"]?)(www\.youtube)([^\"']*)(\\4])(.*)(\[\/youtube\])/siU",
      
"/(\[)(youtube)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/youtube\])/siU",
      
"/(\[)(youtube)(])(www\.)([^\"]*)(\[\/youtube\])/siU",
      
"/(\[)(youtube)(])([^\"]*)(\[\/youtube\])/siU"
    
);
    
$replace_array = array(
      
"<a href=\"http://www.\\6\" target=\"_blank\" rel=\"nofollow\">\\8</a>",
      
"<a href=\"\\5\" target=\"_blank\" rel=\"nofollow\">\\7</a>",
      
"<a href=\"http://www.\\5\" target=\"_blank\" rel=\"nofollow\">www.\\5</a>",
      
"<object width=\"150\" height=\"150\"><param name=\"movie\" value=\"\\4\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"\\4\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"150\" height=\"150\"></embed></object>"
    
);

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: replace youtube url - bbcode - includes.php
« Reply #1 on: October 27, 2010, 03:49:33 PM »
regexp:
Code: [Select]
/\[youtube\](http:\/\/)?(www\.)?youtube\.com\/watch\?v=([^&]+)\[\/youtube\]/i
replace string:
Code: [Select]
http://www.youtube.com/v/\3?fs=1&amp;hl=de_DE&amp;rel=0
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Sunny C.

  • Addicted member
  • ******
  • Posts: 1.806
  • I ♥ 4I
    • View Profile
Re: replace youtube url - bbcode - includes.php
« Reply #2 on: October 27, 2010, 04:18:04 PM »
Thank you, but dont work:
$text preg_replace("/\[youtube\](http:\/\/)?(www\.)?youtube\.com\/watch\?v=([^&]+)\[\/youtube\]/i""<object width=\"150\" height=\"150\"><param name=\"movie\" value=\"\\5?fs=1&amp;hl=de_DE&amp;rel=0\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"\\5?fs=1&amp;hl=de_DE&amp;rel=0\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"150\" height=\"150\"></embed></object>"$text);

I want to be between [youtube] and [/ youtube] can enter the address of a video. There will be no matter what the address looks like. This should be rewritten more generally in the right shape so that the embed code to work.

This work:
$text preg_replace("/\[youtube\](.*)youtube.com\/watch\?v=(.*)\[\/youtube\]/Usi""<object width=\"425\" height=\"344\"><param name=\"movie\" value=\"http://www.youtube.com/v/\\2&hl=de&fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><embed src=\"http://www.youtube.com/v/\\2&hl=de&fs=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"425\" height=\"344\"></embed></object>"$text);