s1yman Posted June 6, 2010 Share Posted June 6, 2010 Hi all, I've got a code that searches a string (an embed script) and strips it down to the youtube video link. $encoded = strchr("$encoded","http://www.you"); $encoded = strrev($encoded); $encoded = strrchr("$encoded","&"); $encoded = strrev($encoded); $encoded = str_replace("-nocookie","","$encoded"); $encoded = str_replace("&","",$encoded); Might be a bit "busy" .. but I'm a rookie, still that works well enough. My problem is that it searches for http://www.you - but if it is not a youtube video it will returns blank (obviously). So my question is, how do I go about stopping it from making my string nothing when it's not a youtube vid? I have tried to play around with if statements, but I'm bit clueless .. any help really appreciated!! Thanks in anticipation Quote Link to comment https://forums.phpfreaks.com/topic/204044-stop-string-returning-false/ Share on other sites More sharing options...
sspoke Posted June 6, 2010 Share Posted June 6, 2010 thats just strings bro there is no conditional operators to return different conditions so you gotta learn some programming basics strchr("$encoded","http://www.you"); to $encoded = strchr($encoded,"http://www.you") == '' ? $encoded : strchr($encoded,"http://www.you"); but it's confusing me why you just use you.. and not just youtube i can go to youporn.com and it will work Quote Link to comment https://forums.phpfreaks.com/topic/204044-stop-string-returning-false/#findComment-1068725 Share on other sites More sharing options...
s1yman Posted June 6, 2010 Author Share Posted June 6, 2010 "learning" is always problem if you don't follow structured courses ... Quote Link to comment https://forums.phpfreaks.com/topic/204044-stop-string-returning-false/#findComment-1068726 Share on other sites More sharing options...
s1yman Posted June 6, 2010 Author Share Posted June 6, 2010 thats just strings bro there is no conditional operators to return different conditions so you gotta learn some programming basics strchr("$encoded","http://www.you"); to $encoded = strchr($encoded,"http://www.you") == '' ? $encoded : strchr($encoded,"http://www.you"); but it's confusing me why you just use you.. and not just youtube i can go to youporn.com and it will work That works .. thanks! the reason for the critera was I need the full url .. and as it's searching the embed link, I couldn't put "http" because that would pull the play url .. maybe i wanted it to cover youporn as well lol cheers for your help bro .. Quote Link to comment https://forums.phpfreaks.com/topic/204044-stop-string-returning-false/#findComment-1068732 Share on other sites More sharing options...
sspoke Posted June 6, 2010 Share Posted June 6, 2010 np bro have fun Quote Link to comment https://forums.phpfreaks.com/topic/204044-stop-string-returning-false/#findComment-1068733 Share on other sites More sharing options...
ignace Posted June 7, 2010 Share Posted June 7, 2010 $url = 'http://www.youtube.com/vid?id=bla'; $urlParts = parse_url($url); if ($urlParts['host'] === 'www.youtube.com' || $urlParts['host'] === 'youtube.com') { //youtube $params = array(); parse_str($urlParts['query'], $params); echo $params['id'];//bla } Quote Link to comment https://forums.phpfreaks.com/topic/204044-stop-string-returning-false/#findComment-1068894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.