Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2011
    Posts
    120
    Thanks
    6
    Thanked 2 Times in 2 Posts

    question on curl and preg_match_all

    First off, this is the first time I've tried to us curl, so I'm kind of confused as to what is wrong in this script.

    I'm using preg_match_all on a part of the page that is only there if the video is still available, but it always echo's out "TEST TEST THIS MOVIE SHOULD NEED TO BE FIXED"....Does this mean I'm doing my preg_match_all wrong? If it is able to find what I've set in preg_match_all, the code should do nothing, but it is always echoing out like the preg_match_all isn't there.

    PHP Code:
    if($version1_source == 'sockshare.com') {
            
    // check to see if video is still embedded on sockshare pages
        
    $target_url $version1;
        
    $ch curl_init();
    curl_setopt($chCURLOPT_USERAGENT$userAgent);
    curl_setopt($chCURLOPT_URL,$target_url);
    curl_setopt($chCURLOPT_FAILONERRORtrue);
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
    curl_setopt($chCURLOPT_AUTOREFERERtrue);
    curl_setopt($chCURLOPT_RETURNTRANSFER,true);
    curl_setopt($chCURLOPT_TIMEOUTfalse);
    $html curl_exec($ch);
    if (!
    $html) {
        echo 
    "<br />cURL error number:" .curl_errno($ch);
        echo 
    "<br />cURL error:" curl_error($ch);
        exit;
        } else {
        
        
    $version1_html file_get_contents("$version1");
        
    preg_match_all('/<div class="site-content">(.*)
    <h1>(.*)
    <strong>(.*)<\/strong>(.*)
    <\/h1>(.*)
    <div class="ad_728x90_top">/s'
    $version1_html$version1_countPREG_SET_ORDER);
        
            if(isset(
    $version1_count) && count($version1_count) == 1) {
            
    // do nothing
            
    } else {
                echo 
    $movie_id;
        echo 
    'TEST TEST THIS MOVIE SHOULD NEED TO BE FIXED<br />';
            }

        }
        
        
        
        } 

    Here is the html that I'm trying to preg_match_all to:

    Code:
    <div class="site-body">
    <div class="site-content">
    <h1>
    I.Am.Number.Four.2011.PPVRip.IFLIX.avi
    <strong>( 391.96 MB )</strong>
    </h1>
    <div class="ad_728x90_top">
    However, the title/size obiviously varies depending on URL. Please help, if you have a moment!

    Thanks!!

  • #2
    New Coder
    Join Date
    Aug 2002
    Location
    Moscow, RU
    Posts
    23
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hello, yup, your preg_match is incorrect.

    Code:
    <?php
    
    $string = '
    <div class="site-body">
    <div class="site-content">
    <h1>
    I.Am.Number.Four.2011.PPVRip.IFLIX.avi
    <strong>( 391.96 MB )</strong>
    </h1>
    <div class="ad_728x90_top">
    ';
    
    preg_match_all('/<div class="site-body">\s*?<div class="site-content">\s*?<h1>\s*?(.*?)<strong>\(\s*?(.*?)\s*?\)<\/strong>\s*?<\/h1>/s', $string, $version1_count, PREG_SET_ORDER);
    
    print_r($version1_count);
    ?>
    you will get name of video in $version1_count[1] and its size in $version1_count[2]. just check any of em or both for their set and that will mean that video here.

    like this

    if ((isset($version1_count[1]) && ($version1_count[1]))) { it's matched } else { not matched }

    Btw - preg_match_all returns array not variable.
    Last edited by Inci; 09-17-2011 at 12:28 AM.

  • #3
    Regular Coder
    Join Date
    Jan 2011
    Posts
    120
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Ahh, well I'm trying to make it check around 25,000 pages at once, and the page titles vary, and I have no way to check it by that. I was hoping to check it by the html there. Can I check it against whether or not that string of html is there?

  • #4
    New Coder
    Join Date
    Aug 2002
    Location
    Moscow, RU
    Posts
    23
    Thanks
    0
    Thanked 1 Time in 1 Post
    hello again, i already gave you the string )

    Code:
    preg_match_all('/<div class="site-body">\s*?<div class="site-content">\s*?<h1>\s*?(.*?)<strong>\(\s*?(.*?)\s*?\)<\/strong>\s*?<\/h1>/s', $version1_html, $version1_count, PREG_SET_ORDER);
    also you need to change this block

    Code:
    if(isset($version1_count) && count($version1_count) == 1) {
            // do nothing
            } else {
                echo $movie_id;
        echo 'TEST TEST THIS MOVIE SHOULD NEED TO BE FIXED<br />';
            }
    to

    Code:
    if ((isset($version1_count[1]) && ($version1_count[1]))) {
            // do nothing
            } else {
                echo $movie_id;
        echo 'TEST TEST THIS MOVIE SHOULD NEED TO BE FIXED<br />';
            }
    hope it will help you.
    Last edited by Inci; 09-17-2011 at 01:03 AM.

  • Users who have thanked Inci for this post:

    MattClark (09-17-2011)

  • #5
    Regular Coder
    Join Date
    Jan 2011
    Posts
    120
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Alright, starting to get it all figured out now. Thanks so much!


  •  

    Posting Permissions

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