I am using this code to download video from you tube (it is a robot.php file used in downloading process)
<?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>');
}
?>
running this, I get error
Deprecated: Function eregi() is deprecated in
D:\wamp\www\u\code\robot.php on line 6
and line 6 is
if(eregi(‘youtube.com|localhost’,$_GET[‘url’]))
searching stackoverflow i got
if (!function_exists('eregi')) {
function eregi($find, $str) {
return stristr($str, $find);
}
}
but i am not sure how to use it? where should i place it?
could any one help me regarding this? how to update this code to match regex and remove errors?
thanks..
As of PHP 5.3.0, the POSIX Regex extension is deprecated in favour of the PCRE extension.
See http://php.net/reference.pcre.pattern.posix for a short overview on migrating your POSIX regex code (
ereg*) to use the PCRE (preg_*) functions, necessary alterations to your regular expressions and limitations of both extensions.Also, you should not use the code that you found. The PHP error is stating that the function exists but is deprecated. The code that you found will do nothing to help.
An example of a common “conversion” might look like:
POSIX
if (eregi('apple|pear')) …PCRE
if (preg_match('/apple|pear/i')) …What was done?
eregi()topreg_match().i(PCRE_CASELESS) was used (to match case-insensitively).