/-6ren">
gpt4 book ai didi

php - 下载youtube文件时将eregi转换为正则表达式

转载 作者:行者123 更新时间:2023-12-03 05:47:58 25 4
gpt4 key购买 nike

我正在使用此代码从您的电子管下载视频(这是在下载过程中使用的robot.php文件)

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

require_once('lib/youtube.lib.php');
if(eregi('youtube.com|localhost',$_GET['url'])){
if(!eregi('www.',$_GET['url'])){
$_GET['url'] = str_replace('http://','http://www.',$_GET['url']);
}
list($video_id,$download_link) = get_youtube($_GET['url']);
?>
<p>
<img src="http://img.youtube.com/vi/<?php echo trim($video_id);?>/1.jpg" alt="Preview 1" class="ythumb" />
<img src="http://img.youtube.com/vi/<?php echo trim($video_id);?>/2.jpg" alt="Preview 2" class="ythumb" />
<img src="http://img.youtube.com/vi/<?php echo trim($video_id);?>/3.jpg" alt="Preview 3" class="ythumb" />
</p>
<p>
<a href="<?php echo trim($download_link);?>" class="ydl" title="Download as FLV">Download FLV</a>
<a href="<?php echo trim($download_link);?>&fmt=18" class="ydl" title="Download as MP4">Download MP4</a>
<a href="<?php echo trim($download_link);?>&fmt=17" class="ydl" title="Download as 3GP">Download 3GP</a>
</p>
<?php
}
else{
die('<span style="color:red;">Sorry, the URL is not recognized..</span>');
}
?>

运行这个,我得到错误

Deprecated: Function eregi() is deprecated in D:\wamp\www\u\code\robot.php on line 6



第6行是

if(eregi('youtube.com|localhost',$_GET['url']))



搜索我得到的stackoverflow
if (!function_exists('eregi')) {
function eregi($find, $str) {
return stristr($str, $find);
}
}

但我不确定如何使用它?我应该放在哪里?

有人可以帮我吗?如何更新此代码以匹配正则表达式并消除错误?

谢谢..

最佳答案

从PHP 5.3.0开始,不推荐使用POSIX Regex扩展,而推荐使用PCRE扩展。

有关迁移POSIX正则表达式代码(ereg*)以使用PCRE(preg_*)函数,对正则表达式的必要更改以及这两个扩展名的限制的简要概述,请参见http://php.net/reference.pcre.pattern.posix

另外,您不应使用找到的代码。 PHP错误表明该函数存在,但已弃用。您找到的代码无济于事。

常见的“转换”示例如下:

POSIX if (eregi('apple|pear')) …
PCRE if (preg_match('/apple|pear/i')) …
做了什么?

  • 匹配功能从eregi()更改为 preg_match()
  • 添加了正则表达式pattern delimiters
  • Pattern modifier i(PCRE_CASELESS)被使用(区分大小写)。
  • 关于php - 下载youtube文件时将eregi转换为正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8965107/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com