Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 链接转换这里失败的是什么,从Youtube提供所有3个链接的缩略图?_Php_Youtube_Strpos - Fatal编程技术网

Php 链接转换这里失败的是什么,从Youtube提供所有3个链接的缩略图?

Php 链接转换这里失败的是什么,从Youtube提供所有3个链接的缩略图?,php,youtube,strpos,Php,Youtube,Strpos,下面的代码为发布为youtube链接的文本提供了youtube缩略图,为什么不允许这样做似乎是非法的htttps://www. 相反,它将输出作为变量$text中的链接 $text=“来自web的链接” if(strpos($text,'https://www.youtube.com“)!==假){ $domas= '; } 如果(STRPO($text,'https://www.yout“)!==假){ $domas= '; } if(strpos($text,'youtu.be')==f

下面的代码为发布为youtube链接的文本提供了youtube缩略图,为什么不允许这样做似乎是非法的htttps://www. 相反,它将输出作为变量$text中的链接

$text=“来自web的链接”

if(strpos($text,'https://www.youtube.com“)!==假){
$domas=
';
} 
如果(STRPO($text,'https://www.yout“)!==假){
$domas=
';
} 
if(strpos($text,'youtu.be')==false){
$domas=$text;
} 
echo$domas;

你到底想要实现什么

strpos(originalText,findThis)
返回编号或false。Number-整数,它基本上是字符串/字符的起始位置。例如,您的原始文本是“Ronalds”,您正在搜索“R”,它将返回整数0,因为字符R位于第0位(将字符串视为一个数组,它是第0个元素)。等等如果您正在查找字符“E”-并且在原始文本中肯定没有这样的字符,那么函数将返回
布尔false

在您的情况下,它可能看起来像这样-如果在原始文本中的某个地方有,那么内部部分将被处理。(代码中的$youtube_id2来自何处?)


你在这里寻找的是你的概念,不是吗?

integer?我查到的地方已经是字符串了。开关大小写可以工作。还有一件事是第一个和第二个条件都是有效的-如果原始文本中有“”(第一个条件),那么它肯定有“”(第二个条件)。在这种情况下,第二个条件中的代码将接管第一个条件中的代码。来吧。试试echo strpos(“Ronalds”,“s”)。结果将是6。整数。
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;