Announcement

Collapse
No announcement yet.

How to scan a webpage and get a string from a part of it...?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scott MacVicar
    replied
    Well its on a remote page and he'll need to use fopen to get it and its not really a security risk..

    Leave a comment:


  • Icheb
    replied
    file_get_contents() relies on allow_url_fopen, which is a security risk.

    Leave a comment:


  • sirspot
    replied
    I guess the question is, do you want to collect the data with no special meaning, or do you want to gather meaningful pairs of values? If it is the latter, then you should loop through the file to make sure you are really getting the pairs you desire (this also allows you to detect improperly formatted data).

    Leave a comment:


  • Scott MacVicar
    replied
    file_get_contents is ideal

    PHP Code:
    <?php
     $contents 
    file_get_contents('http://www.example.com/file.php');
     
    preg_match('#Money Made: (\d+)\\$#si'$contents$matches);
     
    preg_match('#Sales : (\d+)#si'$contents$matches2);
     
    ?>
    You can now use $matches[1] and $matches2[1]

    Leave a comment:


  • AlexanderT
    replied
    Uhmm I'd say Curl & RegEx is your friend here.

    Leave a comment:


  • sirspot
    replied
    Something like this

    PHP Code:
    <?php
    function getValueFromLine($line)
    {
      
    $value 0;
      
    $parts explode(':'$line);
      if(isset(
    $parts[1]))
      {
        
    $value intval($parts[1]);
      }
      return 
    $value;
    }
    $webpage file('http://www.webpage.com/mydata.htm');
    $records = array();
    if(
    is_array($webpage))
    {
      
    $lineCount count($webpage);
      for(
    $i=0;$i<$lineCount;$i++)
      {
        
    $line trim(strip_tags($webpage[$i]));
        
    $words explode(' '$line);
        if(
    is_array($words))
        {
          
    $wordCount count($words);
          
    $j=0;
          
    $found false;
          while((
    $j<$wordCount) && ($found == false))
          {
            
    $word strtolower($words[$j]);
            switch(
    $word)
            {
              case 
    'money'$record['money'] = getValueFromLine($line);
                            
    $found true;
                            break;
              case 
    'sales'$record['sales'] = getValueFromLine($line);
                            
    $found true;
                            break;
            }
            
    $j++;
          }
          if((isset(
    $record['money'])) && (isset($record['sales'])))
          {
            
    array_push($records$record);
            unset(
    $record);
          }
        }
        else
        {
          
    // no words found on this line
        
    }
      }
    }
    else
    {
      
    // could not open webpage
    }
    var_dump($records);
    ?>

    Leave a comment:


  • Dani
    replied
    Hi there,

    You can do that easily with cURL, you can easily find some tutorials with mr google

    ~~

    Leave a comment:


  • How to scan a webpage and get a string from a part of it...?

    Hi,
    I'm trying to make a script that will download a webpage and make a string from only a part of that webpage.

    That script will be to manipulate stats. For example, if the page contain this:

    ----------
    Hi welcome everyone!
    Here is the stats:

    Money made: 40$
    Sales : 4

    End of the string
    ---------

    I would get 2 strings containing:
    string1 = 40
    string2 = 4

    Anyone knows how to do that?

    Thanks,
    Booby

Related Topics

Collapse

  • 2Luke2
    Module to call php code
    by 2Luke2
    I'm trying to create a module that will run a php script. below is my php script. I guess I just don't know well enough how to make that run on the forums. I tried to put the raw data in a static html...
    Wed 13 Feb '13, 7:08am
Working...
X