Jump to content

Simple php twitter script


peoy

Recommended Posts

If you look at the botton of http://getminecraft.net/ you see my latest tweets. The problem is that it shows http://getminecraft.net/%22http://twitter.com/PC_Gamer%22 instead of the original twitter url, that results to a wrong url and wrong site. How can I fix it? so it shows the original twitter url. Here is the script:

 

<?php

$username = "getminecraft";

$prefix = "";

$suffix = "";

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

function parse_feed($feed) {

$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);

$tweet = $stepTwo[0];
$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);

return $tweet;

}

$twitterFeed = file_get_contents($feed);

echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);

?>

Link to comment
Share on other sites

Add a space in your echo line. Like this perhaps:

echo stripslashes($prefix) . " " . parse_feed($twitterFeed) . " " . stripslashes($suffix);

 

That will hopefully break up the link and the text before it, which means the text before it won't also be assigned the hyperlink...

 

Denno

Link to comment
Share on other sites

Thank you very much, but that did not change anything  :shrug::confused:

 

Add a space in your echo line. Like this perhaps:

echo stripslashes($prefix) . " " . parse_feed($twitterFeed) . " " . stripslashes($suffix);

 

That will hopefully break up the link and the text before it, which means the text before it won't also be assigned the hyperlink...

 

Denno

Link to comment
Share on other sites

Im not sure actually, since I got this script from a site, since I wasnt sure how to write a simple twitter script.

 

Thanks.

 

Can you please tell me which parts of the twitter feed correspond to the 3 parts of the echo?

 

Denno

Link to comment
Share on other sites

Well then change the script to only echo one thing at a time.. Or instead of adding the space between each element, add a separator as such:

echo stripslashes($prefix) . " | " . parse_feed($twitterFeed) . " | " . stripslashes($suffix);

 

Then you will clearly see which part belongs to what. Infact, are you able to do that and then upload it to your site so I may see as well?

 

Denno

Link to comment
Share on other sites

I have added | now. As you can see, I dont think they are part of the url. thanks

 

Im not sure actually, since I got this script from a site, since I wasnt sure how to write a simple twitter script.

 

Thanks.

 

Can you please tell me which parts of the twitter feed correspond to the 3 parts of the echo?

 

Denno

Link to comment
Share on other sites

Alright so now we know that the link is being printed using

parse_feed($twitterFeed)

 

Can you also add the extra line you see below:

$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
$tweet = str_replace(""",""", $tweet); //you may nee to add a backslash before the double quote that's inbetween double quotes (the middle argument)

 

Denno

Link to comment
Share on other sites

awesome! it is working very nice! want any credits? Also, if you do a codeclean up on that pure HTML site kit on that site, can add your site url and nick to that site kit  :-* have many uniqe visitors  :)

Alright so now we know that the link is being printed using

parse_feed($twitterFeed)

 

Can you also add the extra line you see below:

$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
$tweet = str_replace(""",""", $tweet); //you may nee to add a backslash before the double quote that's inbetween double quotes (the middle argument)

 

Denno

Link to comment
Share on other sites

awesome! it is working very nice! want any credits? Also, if you do a codeclean up on that pure HTML site kit on that site, can add your site url and nick to that site kit  :-* have many uniqe visitors  :)

 

Absolutely no idea what you're talking about there mate....

 

Denno

Link to comment
Share on other sites

If you go to that site. there is a fan site kit in a html file, if you do a html clean up so it gets valid html.. I can credit you on that site kit thing.. you'll just have to take a look, if you dont understand: thank you anyways! love and hugs!

awesome! it is working very nice! want any credits? Also, if you do a codeclean up on that pure HTML site kit on that site, can add your site url and nick to that site kit  :-* have many uniqe visitors  :)

 

Absolutely no idea what you're talking about there mate....

 

Denno

Link to comment
Share on other sites

Oh right. I'm happy to help you with problems, I'm not going to spend time cleaning your code though to make it look nice, that's something you need to do :).

 

One suggestion though, if you want people to stay on your site, then you should make your external links open in a new window. You should also let people know that the links are to external sites, as I thought it was a navigation bar, which it isn't really..

 

Denno

Link to comment
Share on other sites

Hehe :P thanks.. added target="_blank" now.. gonna find out a clever way to inform people about those extarnal links tomorrw!

 

Oh right. I'm happy to help you with problems, I'm not going to spend time cleaning your code though to make it look nice, that's something you need to do :).

 

One suggestion though, if you want people to stay on your site, then you should make your external links open in a new window. You should also let people know that the links are to external sites, as I thought it was a navigation bar, which it isn't really..

 

Denno

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.