Posted by gerg on 06/24/06 19:17
Arjen wrote:
> McHenry schreef:
>
>> I have a simple task to query a number of pages and read data then
>> save it into a database.
>> Each page has repeating data similar to a listing of stock quotes
>> where each pages lists 100 stocks etc.
>>
>> a) I can query the web and store the page in a variable
>> b) I can update the database with the data
>>
>> I cannot work out the best way to process the variable of the web page
>> to extract the required data, presently it is simply one large string
>> in a variable.
>>
>> Any pointers would be greatly appreciated...
>
>
> Nothing wrong with a large string. Use preg_match or so to filer out the
> data.
>
> Can you give an example of what page u retrieve and what data u want out
> of it ?
>
> arjen
$string = "This is my big ass string of stocks where each stock is
seperated by a space";
$stocks = explode(" ", $string); // create an array out of each element
of the string, and use the space to tell where each new element of the
array begins and ends.
foreach ($stocks as $stock){
$sql = "INSERT INTO mytable (stock // the name of the field in the
table) VALUES (\"$stock\");
$result = mysql_query($sql);
}
Something like that should work. Basically your just breaking up the
string into one array. If the stocks aren't seperated by a space try to
explode by the \n if they are in a list format.
Good luck!
-g-
Navigation:
[Reply to this message]
|