CURL stored to array?

Status
Not open for further replies.

spyderman4g63

New member
Mar 8, 2007
313
2
0
Ohio
www.teamtutorials.com
Another php stupid question.

I can use curl in php to store directly to a file and/or to a variable. Can curl handle storing line-by-line to an array?

I want to be able to parse the file line-by-line, what would be the best way to do this?
 


What are you returning from CURL that you can't parse correctly in and of itself? More info please.


Looking at each line and doing strpos(). Matching certain tags and striping them to store values in a DB. For example

PHP:
if strpos($line,'<div id="title">'){

$title = trim(strip_tags($line));

}
Right now I am saving to cache, reopening to an array and going through a foreach line by line. The file handlers are causing memory issues. I am wonder if I can split them by the newline characters and store to an array?
 
As far as handling the raw text, take a look at fgets() and see if that will work for you.

to parse the tags, you would need something wit regex.
 
Use preg_match_all ... and store it into an array. Then use a for loop to cycle thru the data... eg:

if( !preg_match_all( "/<html>(.+?)<\/html>/is", $curlinput, $output ) ) return false;
$data=$output[1];
for( $i=0; $i<count( $output ); $i++ ){
perform whatever on : $data[$];
}
 
Who says tags are on a single line?

As the others said, learn a bit of regexp. The basics are really not that hard.
 
Status
Not open for further replies.