Question

Following code gives youtube thumbnails to text which is posted as youtube link, why it seems illegal that it doesn't allow htttps://www. instead it brings output as link that is in variable $text.

$text = "link from web"...

if (strpos($text,'https://www.youtube.com') !== false) {

$domas = '               
<a href="'.$file.'">
<img src="http://img.youtube.com/vi/'.$youtube_id2.'/default.jpg" width="100" height="100"></img>
</a>';

} 

if (strpos($text,'https://www.yout') !== false) {

$domas = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="'.$file.'">
<img src="http://img.youtube.com/vi/'.$youtube_id2.'/default.jpg" width="100" height="100"></img>
</a>';

} 
if (strpos($text,'youtu.be') === false) {

$domas = $text;

} 
    echo $domas;
Was it helpful?

Solution

What exactly you want to achieve??

strpos(originalText,findThis) returns the number or false. Number - integer which basically is the the starting position of string/char you are looking in it. For example your original text is "Ronalds" and you are searching for "R", it will return integer 0, because the char R is in the 0th position (think about the string as an array - it is 0th elementh). And so on. If you are looking for char "E" - and there is definetely not such a char in your original text, then the function will return boolean false.

in your condition it could look like this - if in original text somewhere there is https://www.youtube.com then inner part will be processed. (Where does this $youtube_id2 comes from in your code?)

Isnt it switch-case style you`re looking for your conception here?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top