50) { die("No way am i doing more than 50 pages. Sorry mate.");" /> Save CSV to Server (serialize?)

+ Post New Thread
Results 1 to 4 of 4
Coding Thread, Save CSV to Server (serialize?) in Coding and Web Development; Code: 50) { die("No way am i doing more than 50 pages. Sorry mate."); } echo 'name,date,uri,content' . "\r\n"; for($page ...
  1. #1

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29

    Save CSV to Server (serialize?)

    Code:
     50)
    {
    die("No way am i doing more than 50 pages. Sorry mate.");
    }
    
    echo 'name,date,uri,content' . "\r\n";
    for($page = 1; $page <= $max_pages; $page++) 
    	{
    		$url = "http://search.twitter.com/search.atom?&q={$tag}&rpp=100&page={$page}";
    		$xmlstr = file_get_contents($url);
    
    		$xml = new SimpleXMLElement($xmlstr);
    			foreach ($xml->entry as $entry) 
    			{
    
    $twitterdate = $entry->updated;
    $middle = " ";
    $half = (int) ( (strlen($twitterdate)) ); // cast to int incase str length is odd
    $left = substr($twitterdate, 0, $half);
    $right = substr($twitterdate, $half);
    $unixdate = strtotime($left);
    $correctdate = date("d-m-Y H:i", $unixdate);
    
    
    			echo $entry->author->name . "," . $correctdate . "," . $entry->author->uri . ",\"" . strip_tags($entry->content) . "\" \r\n";
    			}
    	}
    This currently saves the RSS feed from the Twitter search to a .CSV file.

    I'd like to not only allow the file to be downloaded but also get it saved to the server. How can I generate the file and once generated post it to the server?


    *****Please excuse my horrible date functions!!!!!!

  2. #2

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29
    Could anyone suggest an alternative?

    My RSS to CSV file below - When the CSV is downloaded I want to save a copy of the file generated in the background to my server?

    Code:
     50)
    {
    die("No way am i doing more than 50 pages. Sorry mate.");
    }
    
    echo 'name,date,uri,content' . "\r\n";
    for($page = 1; $page <= $max_pages; $page++) 
    	{
    		$url = "http://search.twitter.com/search.atom?&q={$tag}&rpp=100&page={$page}";
    		$xmlstr = file_get_contents($url);
    
    		$xml = new SimpleXMLElement($xmlstr);
    			foreach ($xml->entry as $entry) 
    			{
    
    $twitterdate = $entry->updated;
    $middle = " ";
    $half = (int) ( (strlen($twitterdate)) ); // cast to int incase str length is odd
    $left = substr($twitterdate, 0, $half);
    $right = substr($twitterdate, $half);
    $unixdate = strtotime($left);
    $correctdate = date("d-m-Y H:i", $unixdate);
    
    
    			echo $entry->author->name . "," . $correctdate . "," . $entry->author->uri . ",\"" . strip_tags($entry->content) . "\" \r\n";
    			}
    	}
    	
    	
    ?>

  3. #3
    dwhyte85's Avatar
    Join Date
    Mar 2009
    Location
    Berkshire
    Posts
    1,219
    Thank Post
    159
    Thanked 147 Times in 132 Posts
    Rep Power
    103
    fopen to create the file and fwrite to put the contents into the created file.

    so


    $hndl = fopen('/path/to/myfile.csv', 'x');


    //SOME FOR LOOP, WRITE FORMATTED TWITTER DATA eg, x,y,z,1,2,3

    fwrite($hndl, $twitterstringvar);

    //END FOR LOOP

    fclose($hndl);

  4. #4


    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    4,473
    Thank Post
    866
    Thanked 848 Times in 670 Posts
    Rep Power
    196
    Just make sure the path to your serverside file does not contain *any* elements of user input (if it must, sanitise the hell out of them, but it is still a bad idea).

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 4
    Last Post: 2nd April 2009, 02:50 PM
  2. Exchange 2007 Global Address book from CSV
    By benIT in forum Windows
    Replies: 2
    Last Post: 22nd June 2008, 10:35 AM
  3. Import Staff into Sims.net via a CSV
    By stephen.loader in forum MIS Systems
    Replies: 2
    Last Post: 14th January 2008, 11:32 AM
  4. XLS to CSV not working for pupil info
    By MK-2 in forum ICT KS3 SATS Tests
    Replies: 3
    Last Post: 24th January 2007, 01:30 PM
  5. ical file format to csv convert
    By russdev in forum Windows
    Replies: 2
    Last Post: 1st November 2006, 06:22 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •