2010-01-05 98 views
0

我想發佈一個URL到Twitter,但用戶生成的URL和動態...張貼到Twitter的幫助 - 使用PHP

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

我開始與但不要再追實際URL-然後我嘗試了其他幾個,但他們似乎是靜態網址

我必須使用API​​或有沒有辦法讓這個urlencode讀取我們希望用戶發佈的具體網址?

感謝

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"> <img target="Borrow this from someone on twitter" src="PHOTOBUCKET direct URL HERE" alt="TWEET THIS (IMPROVE YOUR SELECTION)" title="" border="0" /></a></p> 

基本上我想要的磁盤後組合,如果你看到「項目= 22」,始終是changing-,所以我想有一個按鈕,其中的代碼將實際閱讀CURRENT網址不僅僅是我在開始時添加的一個靜態網址...這可能嗎?

回答

1

可能是這樣的?

<?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=<?php echo urlencode($post); ?>">tweet this request <small>[<?php echo $post; ?>]</small></a> <br/> 
<?php 
} 
?> 

Liveview at codecookie.net

希望我的理解是正確的!

1

我認爲一個問題可能是你用方括號「[]」圍住了字符串,並且你用句號結束​​了它。

除此之外,我可能會建議使用像htmlentities()或htmlspecialchars()。

或者,您可能想要考慮使用API​​來執行此操作。首先,除非您在其他地方查看,否則無法保證用戶已登錄到Twitter,並且API可讓您使用Twitter進行身份驗證,並且API可能比查詢字符串請求更有可能受到更長的支持。

UPDATE:
我認爲這個問題將在這部分代碼:

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

你調用一個叫做用urlencode功能,但它在代碼的HTML部分,所以PHP不去執行那個函數,而HTML只是簡單地將它解析爲純文本。 你想要這個來替代它:

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

這應該讓PHP代碼解析,並返回已編碼的字符串。

+0

我不在乎認證 - 如果他們沒有帳戶,他們不會發布它仍然不工作,雖然我刪除了括號 – adam 2010-01-05 20:26:55