Jump to content
nesuxro

random video

Recommended Posts

  • Moderators
Posted
random youtube in server meu cum se face??


<?php

//bagam codul clipului in vector
$clipuri = array(
0 => "wK2U0dYZeQI",
1 => "YFK6H_CcuX8",
2 => "ctLnNQOVg0E"
);

//alegem la intamplare un cod din vector
$rand = $clipuri[rand(0,2)];

//afisam clipul
echo '<iframe width="425" height="349" src="http://www.youtube.com/embed/' . $rand . '" frameborder="0" allowfullscreen></iframe>';

?>

Live demo: http://infosource.cz.cc/clipuri.php

  • Downvote 1
Posted

Clipurile le pui in partea asta:


//bagam codul clipului in vector
$clipuri = array(
0 => "wK2U0dYZeQI",
1 => "YFK6H_CcuX8",
2 => "ctLnNQOVg0E"
);

Ce vezi tu aici, este ce vine in link-ul

http://www.youtube.com/watch?v=PoTEnaAI9Fo

, de exemplu, dupa v=. Tu doar pui in continuare, de exemplu:


/bagam codul clipului in vector
$clipuri = array(
0 => "wK2U0dYZeQI",
1 => "YFK6H_CcuX8",
2 => "ctLnNQOVg0E",
3 => "PoTEnaAI9Fo"
);

Mai jos, modifici

//alegem la intamplare un cod din vector
$rand = $clipuri[rand(0,3)];

Practic, linia asta spune sa ia un clip aleatoriu, de la 0 la 3. Daca ai... 1000 de videoclipuri, pui (0,1000). Daca vrei doar... 100 din ele, si alea sunt de la.. 100 la 199, pui (100,199).

Cam atat.

PS: Bravo lui Synthesis.

  • Downvote 1
  • Moderators
Posted
da foarte frumos.iti multumesc dar nu imi dau seama de unde pina unde sa pun linkurile mele

Sa zicem ca avem linkul asta:

http://www.youtube.com/watch?v=aIV2SkMwesU

Codul videoclipului este cel de dupa v=, adica aIV2SkMwesU. Asa, il adaugam in vector.

<?php
$clipuri = array(
0 => "wK2U0dYZeQI"
);
?>

Ne alegem alt clip, de exemplu:

http://www.youtube.com/watch?v=bWXazVhlyxQ

La fel, luam codul, si il adaugam in vector.

<?php
$clipuri = array(
0 => "wK2U0dYZeQI",
1 => "bWXazVhlyxQ"
);
?>

Fii atent la virgula de dupa prima. Virgulele se pun dupa ce declaram o valoare in vector, mai putin la ultima valoare. Sa mai alegem unul, ca asta de mai jos.

http://www.youtube.com/watch?v=MMeP8kIUd60

Il adaugam in vector, si va iesi..

<?php
$clipuri = array(
0 => "wK2U0dYZeQI",
1 => "bWXazVhlyxQ",
2 => "MMeP8kIUd60"
);
?>

Dupa ceva timp de ales clipurile, scriptul ar putea arata ca urmatorul

<?php
$clipuri = array(
0 => "wK2U0dYZeQI",
1 => "bWXazVhlyxQ",
2 => "MMeP8kIUd60",
3 => "wK2U0dYZeQI",
4 => "YFK6H_CcuX8",
5 => "ctLnNQOVg0E"
);
?>

Pentru a afisa o valoare din vector, folosim sintaxa echo $clipuri[numar]. Spre exemplu, daca vrem sa afisam valoarea wK2U0dYZeQI, vom folosi codul urmator:


<?php
echo $clipuri[0];
?>

Dupa, trecem la alegerea unui clip la intamplare din vector. Pentru asta vom folosi functia rand(start, sfarsit), care alege un numar la intamplare intre numarul declarat la start si numarul declarat la sfarsit. In cazul nostru va fi rand(0, 5). Codul pana aici este urmatorul:


<?php
$clipuri = array(
0 => "wK2U0dYZeQI",
1 => "bWXazVhlyxQ",
2 => "MMeP8kIUd60",
3 => "wK2U0dYZeQI",
4 => "YFK6H_CcuX8",
5 => "ctLnNQOVg0E"
);
$rand = $clipuri[rand(0, 5)];
?>

Codul clipului este memorat in variabila $rand. Acum nu ne mai ramane decat sa afisam clipul embeduit.


<?php
$clipuri = array(
0 => "wK2U0dYZeQI",
1 => "bWXazVhlyxQ",
2 => "MMeP8kIUd60",
3 => "wK2U0dYZeQI",
4 => "YFK6H_CcuX8",
5 => "ctLnNQOVg0E"
);
$rand = $clipuri[rand(0, 5)];
echo '<iframe width="425" height="349" src="http://www.youtube.com/embed/' . $rand . '" frameborder="0" allowfullscreen></iframe>';

?>

Am incercat sa explic cat am putut de bine. Daca nu ai inteles ceva, spune-mi.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...