Skip to content

Instantly share code, notes, and snippets.

@bryanmonzon
Created November 11, 2013 17:29
Show Gist options
  • Save bryanmonzon/7416962 to your computer and use it in GitHub Desktop.
Save bryanmonzon/7416962 to your computer and use it in GitHub Desktop.
String Replace Issue. Can you help me out with this?
<?php
/**
* Code block 1
* This block doesn't work. Having "://" in there makes this not work at all.
*/
$vimeo_id = 72170966; //Example ID.
$hash = unserialize(file_get_contents("https://vimeo.com/api/v2/video/$vimeo_id.php")); //Parses JSON to get Video info
$vimeo_thumb = $hash[0]['thumbnail_small']; //this ends up being http://secure-b.vimeocdn.com/ts/153/182/15318283_100.jpg
$vimeo_thumb = str_replace( "http://", "https://", $vimeo_thumb, $temp = 1);
echo $vimeo_thumb; //out puts http://secure-b.vimeocdn.com/ts/153/182/15318283_100.jpg
/**
* Code block 2
* Removing the "://" adds two "s" to the output
*/
$vimeo_id = 72170966; //Example ID.
$hash = unserialize(file_get_contents("https://vimeo.com/api/v2/video/$vimeo_id.php")); //Parses JSON to get Video info
$vimeo_thumb = $hash[0]['thumbnail_small']; //this ends up being http://secure-b.vimeocdn.com/ts/153/182/15318283_100.jpg
$vimeo_thumb = str_replace( "http", "http", $vimeo_thumb, $temp = 1);
echo $vimeo_thumb; //out puts httpss://secure-b.vimeocdn.com/ts/153/182/15318283_100.jpg
@shanaver
Copy link

I think you just need str_replace(find, replace, string) - lose that 4th input

@bryanmonzon
Copy link
Author

Thanks. Didn't work though :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment