Twitter Text (PHP Edition) Library » Examples

Extraction Examples

Source


<?php
$tweet 
'Tweet mentioning @mikenz and referring to his list @mikeNZ/sports and website http://mikenz.geek.nz #awesome';
$data Twitter_Extractor::create($tweet)
  ->
extract();
print_r($data);

Output

  [hashtags] => (
    [0] => awesome
  )

  [urls] => (
    [0] => http://mikenz.geek.nz
  )

  [mentions] => (
    [0] => mikenz
    [1] => mikeNZ
  )

  [replyto] => 
  [hashtags_with_indices] => (
    [0] => (
          [hashtag] => awesome
          [indices] => (
            [0] => 100
            [1] => 108
          )

      )

  )

  [urls_with_indices] => (
    [0] => (
          [url] => http://mikenz.geek.nz
          [indices] => (
            [0] => 78
            [1] => 99
          )

      )

  )

  [mentions_with_indices] => (
    [0] => (
          [screen_name] => mikenz
          [indices] => (
            [0] => 17
            [1] => 24
          )

      )

    [1] => (
          [screen_name] => mikeNZ
          [indices] => (
            [0] => 51
            [1] => 58
          )

      )

  )

Autolink Examples

Source


<?php
$tweet 
'Tweet mentioning @mikenz and referring to his list @mikeNZ/sports and website http://mikenz.geek.nz #awesome';
$html Twitter_Autolink::create($tweet)
  ->
setNoFollow(false)
  ->
addLinks();
echo 
$html;

Markup

Tweet mentioning @<a class="username" href="http://twitter.com/mikenz" rel="external" target="_blank">mikenz</a> and referring to his list @<a class="list" href="http://twitter.com/mikeNZ/sports" rel="external" target="_blank">mikeNZ/sports</a> and website <a class="url" href="http://mikenz.geek.nz" rel="external" target="_blank">http://mikenz.geek.nz</a> <a class="hashtag" href="http://twitter.com/search?q=%23awesome" rel="external" target="_blank">#awesome</a>

Output

Tweet mentioning @mikenz and referring to his list @mikeNZ/sports and website http://mikenz.geek.nz #awesome

Hit Highlighter Examples

Source


<?php
$tweet 
'Tweet mentioning @mikenz and referring to his list @mikeNZ/sports and website http://mikenz.geek.nz #awesome';
$hits  = array(array(7077), array(101108));
$html Twitter_HitHighlighter::create($tweet)
  ->
addHitHighlighting($hits);
echo 
$html;

Markup

Tweet mentioning @mikenz and referring to his list @mikeNZ/sports and <em>website</em> http://mikenz.geek.nz #<em>awesome</em>

Output

Tweet mentioning @mikenz and referring to his list @mikeNZ/sports and website http://mikenz.geek.nz #awesome