Jump to content

HELP! - file_get_contents

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
maros174

maros174

    Newbie

  • Members
  • Pip
  • 2 posts
Hi all,

How can I "fill" the varable $html with the contents from two files(locations), using the same function file_get_contents ?
Below is a part of the code that I use, it is working perfectly - I just need to collect the data from two web addresses (instead of one) and place it inside the variable $html

Any help will be hugely appreciated...

        $html=file_get_contents('SOME-WEB-ADDRESS');

        $pattern="|<tr[^>]+tip='D'>(.*)</tr+>|U";

        preg_match_all($pattern, $html, $elements);

        $MasterData=array();

        

        foreach($elements[1] AS $ei => $element){

            $pattern="|Model=(.*)'|U";

            preg_match_all($pattern, $element, $Info);

            $pattern="|<td+>(.*)</td+>|U";

            preg_match_all($pattern, $element, $MultiData);

  

            foreach($MultiData[1] AS $tdi => $Data)

                $MasterData[$Info[1][0]][$tdi]=$Data;

        }

        

        foreach($Data AS $oznaka => $data1){[COLOR="Silver"][I]....and the code goes on.....[/I][/COLOR]


#2
Jacki

Jacki

    Learning Programmer

  • Members
  • PipPipPip
  • 80 posts
file_get_contents() return a string, you can concatenate the two string:
$html = file_get_contents('page1').file_get_contents('page2');
but I think it's useless.. what does your script do?
You can also make a function that contain your script and you use it for the two pages...
Posted Image

Posted Image

#3
maros174

maros174

    Newbie

  • Members
  • Pip
  • 2 posts
Thanks. It worked like a charm.
The script collects stock market data from two pages, processes it and stores it in a database.