views:

201

answers:

3

I am trying to post a url to twitter but the url is user generated and dynamic...

<a href="http://twitter.com/?status=[urlencode('I'd like to borrow this item @neighborrow')].">TWEET THIS REQUEST</a> 

i started with that but its not catching the actual url- then i tried a few others but they seem to be for static urls

do i have to use the api or is there a way for this urlencode to read the specific url we want the users to publish?

thanks

UPDATE

<a href="http://twitter.com/?status=urlencode('I'd like to borrow this item @neighborrow')">TWEET THIS REQUEST</a> 
                <p><a href="http://twitter.com/home?status=I'd like to borrow this item @neighborrow http://http://neighborrow.com/wanted.php?item=22"&gt; <img target="Borrow this from someone on twitter" src="PHOTOBUCKET direct URL HERE" alt="TWEET THIS (IMPROVE YOUR SELECTION)" title="" border="0" /></a></p>

basically i want a combination of both- if you see "item=22" that is always changing- so i want a button where the code will actually read the CURRENT url not just a static one i added at the beginning... is this possible?

+1  A: 

I think a problem might be that you used "[ ]" the square brackets to surround the string, and you ended it with a period.

Other than that, I might suggest using something like htmlentities () or htmlspecialchars().

Alternatively, you might want to look into using the API to do this. For one thing, unless you're checking somewhere else, there's no way to guarantee the user is signed into twitter, and the API allows you to authenticate with twitter, plus the API is more likely to be supported longer than the query string request.

UPDATE:
I think the problem would be in this part of the code:

<a href="http://twitter.com/?status=urlencode('I'd like to borrow this item @neighborrow')">TWEET THIS REQUEST</a>

You call a function called urlencode, but it's in the HTML part of the code, so the PHP is not going to execute that function, and the HTML simply parses it as plain text. You'd want to replace it with this:

<a href="http://twitter.com/?status=&lt;?php echo (urlencode('I'd like to borrow this item @neighborrow')) ?>">TWEET THIS REQUEST</a>

That should let the php code parse that and return the encoded string.

chustar
i dont care about authenticating- if they dont have an account they wont post it- still not working though i removed the brackets
adam
+1  A: 

There's a pretty handy PHP Twitter API library here: http://lab.arc90.com/2008/06/03/php-twitter-api-client/

That'll make sure you don't have to solve problems that have already been solved and you can concentrate on writing your code.

Mr-sk
+1  A: 

probably something like this?

<?php
 $posts = array (
      'i\'d like to borrow this item @neighborrow',
      'test this very carefully',
      'enough!!!'
     );

 foreach( $posts as $post )
 {
?>

  <a href="http://twitter.com/?status=&lt;?php echo urlencode($post); ?>">tweet this request <small>[<?php echo $post; ?>]</small></a> <br/>
<?php
 }
?>

Liveview at codecookie.net

hope i understood it correct!

Dominik K.