2012-01-21 24 views
1

我真的很陌生,PHP和JavaScript,我做了一个PHP发布脚本,我想添加twitter链接到用户名。我把JavaScript放在头上,但没有运气。我遵循所有的方向,但我无法实现它的工作。这是我的PHP:在PHP中使用Twitter linkify

<form align="center" method='post' action='add.php'> 
    <p>Your status:</p> 
    <textarea name='body' rows='5' cols='40' wrap=VIRTUAL></textarea> 
    <p> What color is a banana? (lowercase) </p> 
    <input type="text" class="blah" name="age" /> 
    <input align="center" type="submit" class="submit" value="Post" disabled="disabled"/> 
</form> 
<script type="text/javascript"> 
$('.blah').change(function() { 
    $(".submit").attr('disabled', $(this).val() != "yellow"); 
}).change(); 
</script> 
<?php 
$posts = show_posts($_SESSION['userid']); 
if (count($posts)){ 
?> 
<table class="imagetable"> 
    <table align="center" border='0' cellspacing='0' cellpadding='5' width='300'> 
<?php 
foreach ($posts as $key => $list){ 
    echo "<tr valign='middle'>\n"; 
    echo "<td>".$list['body'] ."<br/>\n  "; 
    echo "<small>".$list['stamp'] ."</small><hr></td>\n"; 
    echo "</tr>\n"; 
} 
?> 
    </table> 
<?php 
}else{ 
?> 
    <p><b>You haven't posted anything yet!</b></p> 
<?php 
} 
?> 
</body> 
</html> 

这是<head>

<script type="text/javascript"> 
twttr.anywhere(function (T) { 
    T.linkifyUsers(); 
}); 
</script> 

所以是有人类型的 “喜@stackoverflow” @stackoverflow将链接到Twitter的个人资料页?

回答

1

欢迎使用PHP!

在使用之前,您需要在您的页面中包含Twitter JavaScript库。

像这样:

<script src="http://platform.twitter.com/anywhere.js?id=YOUR_API_KEY&v=1" type="text/javascript"></script> 
  • this页面以了解如何获得API密钥。
  • 查看this的页面了解更多关于的任何信息