0

I have problem youtube video and thumbnails block in our country and I want to run youtube api for getting these data , but problem is thumbnails links show like these link

enter image description here

I want to its show through my site link with my server like

https://img.example.com/vi/T0Jqdjbed40/default.jpg

I try to replace url with string replace function but its not work please tell me how to run through my site link like some site show like playit , vube.pk , flix

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Sameed Alam Qureshi
  • 293
  • 1
  • 3
  • 15

1 Answers1

0

As a purely theoretical thing, you can replace sections of a string using the str_replace function:

str_replace(
    "https://i.ytimg.com/vi/T0Jqdjbed40/default.jpg",
    "://i.ytimg.com", "://img.example.com");

This will keep the http:// or https:// protocol in place.


For your use case, again purely theoretically, you would want to download the resource yourself, and then provide it to the end user. To get the data using file_get_contents for example:

$data = file_get_contents('http://www.example.com/');

You culd then potentially embed the image data directly into the page itself - see this SO question: Can I embed a .png image into an html page?

You should probably check youtube's terms of service before attempting anything...

Community
  • 1
  • 1
enigma
  • 3,476
  • 2
  • 17
  • 30
  • yes i already check it replace function but after replace its not show image – Sameed Alam Qureshi Apr 25 '15 at 11:44
  • @SameedAlam that's because `https://img.example.com/vi/T0Jqdjbed40/default.jpg` probably doesn't exist, you haven't created it. Try putting it in your web browser - the image needs to link to a file that actually exists. The second half of my answer is important. – enigma Apr 25 '15 at 11:47