SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Think you can make this better?

    This function will eventually go in my forum of useful functions, however I am wondering if there is a faster way to do it.



    If you want to see what this does you can visit the working script.


    PHP Code:


    <? 

    /*


    Use this function CAREFULLY. 


    +--------------------------------+
    |---   THIS CAN BE ILLEGAL.  ----|
    +--------------------------------+


    I am using the sitepoint home page to demo, and
    I hope they don't get made at me     :-}


    Anywho, this is a content ripping function.
    It's slow as hell, but I am sure it could be
    improved - i am open to suggestions 


    */



    function get_content($search_array,$searchStr,$open,$close,$limit) {

        if(!
    $search_array || !$searchStr || !$open || !$close) {
            return 
    false;
        }

        
    $i 0;
        
        foreach(
    $search_array AS $line) { 

            if ( 
    strstr($line$searchStr) ) { 

                
    $pos strpos ($line$open);
                
    $left_cut substr_replace ($line''0$pos+strlen($open) ) ;
            
                
    $pos2 strpos ($left_cut$close);
                
    $all_cut substr_replace ($left_cut''$pos2, -1) ;
                
                
    $content[] = $all_cut;
                
    $i++;
            } 
            
            if(
    $limit && ($i == $limit) ) {
                return 
    $content;
            }
        } 
        
        return 
    $content;
        

    }

    // USAGE

    $source        file("http://www.sitepoint.com/"); 
    $line_flag     'featureTitleLink'
    $open_content  '<p>';
    $close_content '<br>';
    $total_limit   6;

    if( 
    $my_content get_content($source,$line_flag,$open_content,$close_content,$total_limit) ) {

        foreach (
    $my_content as $v) {
            echo ( 
    $v "</a><br>\n" );
        }

    } else {

        echo(
    'no content');
        
    }


    ?>
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How you can do what better? Grab all the content from a given site and display a portion between certain tags?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    How you can do what better? Grab all the content from a given site and display a portion between certain tags?
    Yeah, cause right now this goes very slow.
    -Jeff Minard | jrm.cc - Battlefield 2 Stats


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
  •