SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Preg Replace

  1. #1
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Preg Replace

    I have a few questions:

    http://keepvid.com/?url=http://www.y...?v=O5I3RPbS8aI

    Basically, I want to get the contents of this URL and parse the first download link
    Code:
    http://keepvid.com/save-video.flv?http%3A%2F%2Fv13.lscache7.googlevideo.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%26itag%3D5%26ipbits%3D0%26sver%3D3%26expire%3D1243936800%26key%3Dyt1%26signature%3D3D869CF6DA8FBED4309CB713E675F28D4E089B6A.C43300CBA22606945F1040D868F3D9233E44D894%26id%3D3b923744f6d2f1a2
    into something like:

    <video>http://keepvid.com/save-video.flv?http%3A%2F%2Fv13.lscache7.googlevideo.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%26itag%3D5%26ipbits%3D0%26sver%3D3%26expire%3D1243936800%26key%3Dyt1%26signature%3D3D869CF6DA8FBED4309CB713E675F28D4E089B6A.C43300CBA22606945F1040D868F3D9233E44D894%26id%3D3b923744f6d2f1a2</video>

    How would I do this? Preg replace? I'm terrible at that and would appreciate any help!

    Regards!
    :-)

  2. #2
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    Use parse URL

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    echo urldecode(
        
    parse_url(
            
    'http://keepvid.com/save-video.flv?http%3A%2F%2Fv13.lscache7.googlevideo.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%26itag%3D5%26ipbits%3D0%26sver%3D3%26expire%3D1243936800%26key%3Dyt1%26signature%3D3D869CF6DA8FBED4309CB713E675F28D4E089B6A.C43300CBA22606945F1040D868F3D9233E44D894%26id%3D3b923744f6d2f1a2',
            
    PHP_URL_QUERY
        
    )
    ); 
    #http://v13.lscache7.googlevideo.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag&itag=5&ipbits=0&sver=3&expire=1243936800&key=yt1&signature=3D869CF6DA8FBED4309CB713E675F28D4E089B6A.C43300CBA22606945F1040D868F3D9233E44D894&id=3b923744f6d2f1a2
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes but I want to fopen the url http://keepvid.com/?url=http://www.y...?v=O5I3RPbS8aI and grab the save-video.flv link..
    :-)

  5. #5
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Ah.
    PHP Code:
    <?php
    $oXPath 
    = new DOMXPath(@DOMDocument::loadHTMLFile('http://keepvid.com/?url=http://www.youtube.com/watch?v=O5I3RPbS8aI'));
    printf(
        
    'http://keepvid.com%s',
        
    $oXPath->query("//a[contains(@href,'save-video.flv')]")->item(0)->getAttribute('href')
    ); 
    #http://keepvid.com/save-video.flv?http%3A%2F%2Fv13.lscache7.googlevideo.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%26itag%3D5%26ipbits%3D0%26sver%3D3%26expire%3D1243958400%26key%3Dyt1%26signature%3D8EF6DFBAA388F1AC66A26DBCBE4DE097A2F342A8.34DF7445867170E0B731E515F8C48D9B9FF4F66F%26id%3D3b923744f6d2f1a2
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  6. #6
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, so say I want to grab the URL as a user friendly URL from the keepvid page and then parse it to the variable $video So $video = http://keepvid.com/save-video.flv?ht...ack%3Fip%3D0.0 .0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%26itag%3D5%26ipbits% 3D0%26sver%3D3%26expire%3D1243936800%26key%3Dyt1%26signature%3D3D869CF6DA8FBED 4309CB713E675F28D4E089B6A.C43300CBA22606945F1040D868F3D9233E44D894%26id%3D3b92 3744f6d2f1a2 Thanks for all your help.
    :-)

  7. #7
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Was there a question in there?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •