Eregi Deprecated Help

Discussion in 'PHP' started by sonu21, Jan 15, 2012.

  1. #1
    Hello Guys,I want help from you.It shows error "eregi is deprecated"
    
    <?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="download.php?url=<?php echo urlencode($download_link);?>" class="ydl" title="Download as FLV">Download FLV</a>
        <a href="download.php?url=<?php echo urlencode($download_link.'&fmt=18');?>" class="ydl" title="Download as MP4">Download MP4</a>
        <a href="download.php?url=<?php echo urlencode($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>');
    }
    ?>
    
    
    
    PHP:
    How can I solve it ?
     
    sonu21, Jan 15, 2012 IP
  2. waynewex

    waynewex Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You'll need to switch from eregi to a preg_match solution that does the same thing.
     
    waynewex, Jan 15, 2012 IP
  3. sonu21

    sonu21 Member

    Messages:
    102
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #3
    Thanks For your response but,I don't know where to change it.I had posted the code also.Can you replace it with "preg_match" & posted it again.It will be great Thanks For you if you do this.


    Thanks & Regards,:cool:
    Sonu21
     
    sonu21, Jan 15, 2012 IP
  4. modz

    modz Well-Known Member

    Messages:
    95
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #4
    Be sure to test the code in real situations. I might made a mistake. I do not test what I write in this forum.

    
    <?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(preg_match('/(.*)(youtube.com|localhost)(.*)/i',$_GET['url'])){
        if(!preg_match('/(.*)www\.(.*)/i',$_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="download.php?url=<?php echo urlencode($download_link);?>" class="ydl" title="Download as FLV">Download FLV</a>
        <a href="download.php?url=<?php echo urlencode($download_link.'&fmt=18');?>" class="ydl" title="Download as MP4">Download MP4</a>
        <a href="download.php?url=<?php echo urlencode($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>');
    }
    ?>
    
    
    
    PHP:
     
    modz, Jan 16, 2012 IP
  5. sonu21

    sonu21 Member

    Messages:
    102
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #5
    Thanks! Modz It works.
     
    sonu21, Jan 17, 2012 IP