Use Twitter linkify in PHP posts

308 Views Asked by At

I'm really new to PHP and JavaScript and I made a PHP posting script and I wanted to add twitter linkify to usernames. I put the javascript in the head but no luck. I followed all the directions but I just can't get it to work. Here's my PHP:

<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>

This is in the <head>:

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

So is someone types in "Hi @stackoverflow" @stackoverflow will link to the Twitter profile page?

1

There are 1 best solutions below

0
On BEST ANSWER

Welcome to PHP!

You need to include the Twitter JavaScript library to your page, before using it.

Like this:

<script src="http://platform.twitter.com/anywhere.js?id=YOUR_API_KEY&v=1" type="text/javascript"></script>
  • See this page to find out how to get an API key.
  • See this page to learn more about anywhere.