This is a simple PHP snippet which will turn Twitter #Tags into link’s. This technique requires a regular expression function called preg_replace().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
  // Setup the example string
  $text = 'Am example string containing some #hash #tags';
  // Apply the regular expression
  $text = preg_replace(
    '/\s#(\w+)/',
    '<a href="http://search.twitter.com/search?q=%23$1">#$1</a> ',
    $text
  ); //turn twitter #tags into links
  // Trace the string
  print $text;
  // The ouput string:
  // Am example string containing some
  //    <a href="http://search.twitter.com/search?q=%23hash">#hash</a>
  //    <a href="http://search.twitter.com/search?q=%23tags">#tags</a>
?>