Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Write exploded string to file
Old 02-17-2009, 11:31 PM Write exploded string to file
Junior Talker

Posts: 3
Name: T Nielsen
Trades: 0
Hello folks,

One of the bloggers on my website recently started twitter-ing, and he's hysterical, so I'd like to figure out a way to post his twitter to a page on the website. Small problem: not all of his tweets are necessarily appropriate for the medium, so I'm trying to write code to generate a .txt file with his most recent 15 tweets for someone to sort through and post as would be appropriate.

I've borrowed and edited some code to pull the twitter via rss, and it works like a gem up until comment //FIDDLESTICKS!!

As far as I understand it, being a newbie, that the explode function creates an array... I'd like to figure out a way to write it to a file when the script is run.

Thanks SO much for your help!

Cheers!

Code:
<?php
/*
Template Name: Twitter
*/
?>

<?php get_header(); ?>

<?php 

// Define username and how much to pull; cleanup output with listing

$username = "TWITTERUSER"; 
$limit = "15"; 
$prefix = "<ul>";
$suffix = "</ul>";
$pretweet = "<li>";
$posttweet = "</li>";

$feed = "http://search.twitter.com/search.atom?q=from:" . $username . " . $limit . ";

function parse_feed($feed, $prefix, $pretweet, $posttweet, $suffix) {

//Beautify.

$feed = str_replace("&lt;", "<", $feed);
$feed = str_replace("&gt;", ">", $feed);
$feed = str_replace("&amp;", "&", $feed);
$feed = str_replace("&quot;", "\"", $feed);

//Create a clean version of the code in html and overwrite the $feed string telling it to use cont... as the dynamite.
$clean = explode("<content type=\"html\">", $feed);

//Establish the number of times the php should loop
$amount = count($clean) - 1;

echo $prefix;

//Looptastic magic

for ($i = 1; $i <= $amount; $i++) {


$cleaner = explode("</content>", $clean[$i]);
echo $pretweet;
echo $cleaner[0];
echo $posttweet;

}

echo $suffix;

}

$twitterFeed = file_get_contents($feed);
//This is the part that seems to print out the results; it can't be saved as a string, which I tried in the next line...
parse_feed($twitterFeed, $prefix, $pretweet, $posttweet, $suffix);

/* FAILED: echo $filecontents or die("DARN!!"); */

// FIDDLESTICKS!!

/* $codex = "RecentTwitters.txt";
 
$codexhandle = fopen($codex, 'a') or die("Cannot perform up to standard. I need the attention of a webcoder.");

fwrite($codexhandle, $filecontents);

fclose($codexhandle);

echo "<br /> <br />D.V. 'Tis done."; */ ?>

<?php get_footer(); ?>
nielsen is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-18-2009, 03:09 AM Re: Write exploded string to file
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
I don't see $codex defined anywhere, which makes fopen fail.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-18-2009, 04:29 PM Re: Write exploded string to file
Junior Talker

Posts: 3
Name: T Nielsen
Trades: 0
$codex is defined 5th line from the bottom.

"$codex = RecentTwitters.txt"
nielsen is offline
Reply With Quote
View Public Profile
 
Old 02-18-2009, 04:41 PM Re: Write exploded string to file
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
Oh apparently I read like a compiler, I skip the comments. :P

The lines /* $codex = "RecentTwitters.txt"; to echo "<br /> <br />D.V. 'Tis done."; */ have been commented out, so they aren't evaluated.

Just remove the /* and */.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-18-2009, 07:35 PM Re: Write exploded string to file
Junior Talker

Posts: 3
Name: T Nielsen
Trades: 0
I commented them out because they don't work; i tried to make the "parse_feed" a string, but it didn't like it; the string was called "$filecontents" and it won't write tot he document.
nielsen is offline
Reply With Quote
View Public Profile
 
Old 02-19-2009, 03:30 AM Re: Write exploded string to file
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
You mean you tried:
$filecontents = parse_feed($twitterFeed, $prefix, $pretweet, $posttweet, $suffix);

If that didn't work, could you post the parse_feed function here?
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Write exploded string to file
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23675 seconds with 12 queries