Jump to content

Stop string returning false


s1yman

Recommended Posts

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!!  :confused:

 

Thanks in anticipation :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ..

Link to comment
Share on other sites

$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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.