3v4l.org

run code in 300+ PHP versions simultaneously
<?php $twitter_handle = "twitter"; function buildBaseString($baseURI, $method, $params) { $r = array(); ksort($params); foreach($params as $key=>$value){ $r[] = "$key=" . rawurlencode($value); } return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r)); } function buildAuthorizationHeader($oauth) { $r = 'Authorization: OAuth '; $values = array(); foreach($oauth as $key=>$value) $values[] = "$key=\"" . rawurlencode($value) . "\""; $r .= implode(', ', $values); return $r; } $url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; $oauth_access_token = "your own"; $oauth_access_token_secret = "your own"; $consumer_key = "your own"; $consumer_secret = "your own"; $oauth = array( 'oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0', 'screen_name' => $twitter_handle); $base_info = buildBaseString($url, 'GET', $oauth); $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret); $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true)); $oauth['oauth_signature'] = $oauth_signature; // Make Requests $header = array(buildAuthorizationHeader($oauth), 'Content-Type: application/json', 'Expect:'); $options = array( CURLOPT_HTTPHEADER => $header, //CURLOPT_POSTFIELDS => $postfields, CURLOPT_HEADER => false, CURLOPT_URL => $url . '?screen_name=' . $twitter_handle, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false); $feed = curl_init(); curl_setopt_array($feed, $options); $json = curl_exec($feed); curl_close($feed); $decode = json_decode($json, true); //getting the file content as array echo '<ul>'; foreach($decode as $tweet) { $tweet_text = $tweet["text"]; echo '<li>'; echo $tweet_text; echo '</li>'; } echo '</ul>'; $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; $reg_exHash = "/#([a-z_0-9]+)/i"; $reg_exUser = "/@([a-z_0-9]+)/i"; echo '<ul>'; foreach ($decode as $tweet) { $tweet_text = $tweet["text"]; //get the tweet // make links link to URL // http://css-tricks.com/snippets/php/find-urls-in-text-make-links/ if(preg_match($reg_exUrl, $tweet_text, $url)) { // make the urls hyper links $tweet_text = preg_replace($reg_exUrl, "<a href='{$url[0]}'>{$url[0]}</a> ", $tweet_text); } if(preg_match($reg_exHash, $tweet_text, $hash)) { // make the hash tags hyper links https://twitter.com/search?q=%23truth $tweet_text = preg_replace($reg_exHash, "<a href='https://twitter.com/search?q={$hash[0]}'>{$hash[0]}</a> ", $tweet_text); // swap out the # in the URL to make %23 $tweet_text = str_replace("/search?q=#", "/search?q=%23", $tweet_text ); } if(preg_match($reg_exUser, $tweet_text, $user)) { $tweet_text = preg_replace("/@([a-z_0-9]+)/i", "<a href='http://twitter.com/$1'>$0</a>", $tweet_text); } // display each tweet in a list item echo "<li>" . $tweet_text . "</li>"; } echo '</ul>'; ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 86, Position 2 = 93
Branch analysis from position: 86
2 jumps found. (Code = 78) Position 1 = 87, Position 2 = 93
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 86
Branch analysis from position: 86
Branch analysis from position: 93
2 jumps found. (Code = 77) Position 1 = 100, Position 2 = 163
Branch analysis from position: 100
2 jumps found. (Code = 78) Position 1 = 101, Position 2 = 163
Branch analysis from position: 101
2 jumps found. (Code = 43) Position 1 = 109, Position 2 = 122
Branch analysis from position: 109
2 jumps found. (Code = 43) Position 1 = 128, Position 2 = 147
Branch analysis from position: 128
2 jumps found. (Code = 43) Position 1 = 153, Position 2 = 159
Branch analysis from position: 153
1 jumps found. (Code = 42) Position 1 = 100
Branch analysis from position: 100
Branch analysis from position: 159
Branch analysis from position: 147
Branch analysis from position: 122
Branch analysis from position: 163
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 163
Branch analysis from position: 93
filename:       /in/u52fp
function name:  (null)
number of ops:  166
compiled vars:  !0 = $twitter_handle, !1 = $url, !2 = $oauth_access_token, !3 = $oauth_access_token_secret, !4 = $consumer_key, !5 = $consumer_secret, !6 = $oauth, !7 = $base_info, !8 = $composite_key, !9 = $oauth_signature, !10 = $header, !11 = $options, !12 = $feed, !13 = $json, !14 = $decode, !15 = $tweet, !16 = $tweet_text, !17 = $reg_exUrl, !18 = $reg_exHash, !19 = $reg_exUser, !20 = $hash, !21 = $user
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'twitter'
   22     1        ASSIGN                                                   !1, 'https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fuser_timeline.json'
   24     2        ASSIGN                                                   !2, 'your+own'
   25     3        ASSIGN                                                   !3, 'your+own'
   26     4        ASSIGN                                                   !4, 'your+own'
   27     5        ASSIGN                                                   !5, 'your+own'
   29     6        INIT_ARRAY                                       ~28     !4, 'oauth_consumer_key'
   30     7        INIT_FCALL                                               'time'
          8        DO_ICALL                                         $29     
          9        ADD_ARRAY_ELEMENT                                ~28     $29, 'oauth_nonce'
   31    10        ADD_ARRAY_ELEMENT                                ~28     'HMAC-SHA1', 'oauth_signature_method'
   32    11        ADD_ARRAY_ELEMENT                                ~28     !2, 'oauth_token'
   33    12        INIT_FCALL                                               'time'
         13        DO_ICALL                                         $30     
         14        ADD_ARRAY_ELEMENT                                ~28     $30, 'oauth_timestamp'
   34    15        ADD_ARRAY_ELEMENT                                ~28     '1.0', 'oauth_version'
   35    16        ADD_ARRAY_ELEMENT                                ~28     !0, 'screen_name'
   29    17        ASSIGN                                                   !6, ~28
   37    18        INIT_FCALL                                               'buildbasestring'
         19        SEND_VAR                                                 !1
         20        SEND_VAL                                                 'GET'
         21        SEND_VAR                                                 !6
         22        DO_FCALL                                      0  $32     
         23        ASSIGN                                                   !7, $32
   38    24        INIT_FCALL                                               'rawurlencode'
         25        SEND_VAR                                                 !5
         26        DO_ICALL                                         $34     
         27        CONCAT                                           ~35     $34, '%26'
         28        INIT_FCALL                                               'rawurlencode'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $36     
         31        CONCAT                                           ~37     ~35, $36
         32        ASSIGN                                                   !8, ~37
   39    33        INIT_FCALL                                               'base64_encode'
         34        INIT_FCALL                                               'hash_hmac'
         35        SEND_VAL                                                 'sha1'
         36        SEND_VAR                                                 !7
         37        SEND_VAR                                                 !8
         38        SEND_VAL                                                 <true>
         39        DO_ICALL                                         $39     
         40        SEND_VAR                                                 $39
         41        DO_ICALL                                         $40     
         42        ASSIGN                                                   !9, $40
   40    43        ASSIGN_DIM                                               !6, 'oauth_signature'
         44        OP_DATA                                                  !9
   43    45        INIT_FCALL                                               'buildauthorizationheader'
         46        SEND_VAR                                                 !6
         47        DO_FCALL                                      0  $43     
         48        INIT_ARRAY                                       ~44     $43
         49        ADD_ARRAY_ELEMENT                                ~44     'Content-Type%3A+application%2Fjson'
         50        ADD_ARRAY_ELEMENT                                ~44     'Expect%3A'
         51        ASSIGN                                                   !10, ~44
   44    52        FETCH_CONSTANT                                   ~46     'CURLOPT_HTTPHEADER'
         53        INIT_ARRAY                                       ~47     !10, ~46
   46    54        FETCH_CONSTANT                                   ~48     'CURLOPT_HEADER'
   44    55        ADD_ARRAY_ELEMENT                                ~47     <false>, ~48
   47    56        FETCH_CONSTANT                                   ~49     'CURLOPT_URL'
         57        CONCAT                                           ~50     !1, '%3Fscreen_name%3D'
         58        CONCAT                                           ~51     ~50, !0
         59        ADD_ARRAY_ELEMENT                                ~47     ~51, ~49
   48    60        FETCH_CONSTANT                                   ~52     'CURLOPT_RETURNTRANSFER'
   44    61        ADD_ARRAY_ELEMENT                                ~47     <true>, ~52
   49    62        FETCH_CONSTANT                                   ~53     'CURLOPT_SSL_VERIFYPEER'
   44    63        ADD_ARRAY_ELEMENT                                ~47     <false>, ~53
         64        ASSIGN                                                   !11, ~47
   50    65        INIT_FCALL_BY_NAME                                       'curl_init'
         66        DO_FCALL                                      0  $55     
         67        ASSIGN                                                   !12, $55
   51    68        INIT_FCALL_BY_NAME                                       'curl_setopt_array'
         69        SEND_VAR_EX                                              !12
         70        SEND_VAR_EX                                              !11
         71        DO_FCALL                                      0          
   52    72        INIT_FCALL_BY_NAME                                       'curl_exec'
         73        SEND_VAR_EX                                              !12
         74        DO_FCALL                                      0  $58     
         75        ASSIGN                                                   !13, $58
   53    76        INIT_FCALL_BY_NAME                                       'curl_close'
         77        SEND_VAR_EX                                              !12
         78        DO_FCALL                                      0          
   55    79        INIT_FCALL                                               'json_decode'
         80        SEND_VAR                                                 !13
         81        SEND_VAL                                                 <true>
         82        DO_ICALL                                         $61     
         83        ASSIGN                                                   !14, $61
   57    84        ECHO                                                     '%3Cul%3E'
   58    85      > FE_RESET_R                                       $63     !14, ->93
         86    > > FE_FETCH_R                                               $63, !15, ->93
   59    87    >   FETCH_DIM_R                                      ~64     !15, 'text'
         88        ASSIGN                                                   !16, ~64
   60    89        ECHO                                                     '%3Cli%3E'
   61    90        ECHO                                                     !16
   62    91        ECHO                                                     '%3C%2Fli%3E'
   58    92      > JMP                                                      ->86
         93    >   FE_FREE                                                  $63
   64    94        ECHO                                                     '%3C%2Ful%3E'
   66    95        ASSIGN                                                   !17, '%2F%28http%7Chttps%7Cftp%7Cftps%29%5C%3A%5C%2F%5C%2F%5Ba-zA-Z0-9%5C-%5C.%5D%2B%5C.%5Ba-zA-Z%5D%7B2%2C3%7D%28%5C%2F%5CS%2A%29%3F%2F'
   67    96        ASSIGN                                                   !18, '%2F%23%28%5Ba-z_0-9%5D%2B%29%2Fi'
   68    97        ASSIGN                                                   !19, '%2F%40%28%5Ba-z_0-9%5D%2B%29%2Fi'
   70    98        ECHO                                                     '%3Cul%3E'
   71    99      > FE_RESET_R                                       $69     !14, ->163
        100    > > FE_FETCH_R                                               $69, !15, ->163
   72   101    >   FETCH_DIM_R                                      ~70     !15, 'text'
        102        ASSIGN                                                   !16, ~70
   76   103        INIT_FCALL                                               'preg_match'
        104        SEND_VAR                                                 !17
        105        SEND_VAR                                                 !16
        106        SEND_REF                                                 !1
        107        DO_ICALL                                         $72     
        108      > JMPZ                                                     $72, ->122
   79   109    >   INIT_FCALL                                               'preg_replace'
        110        SEND_VAR                                                 !17
        111        ROPE_INIT                                     5  ~76     '%3Ca+href%3D%27'
        112        FETCH_DIM_R                                      ~73     !1, 0
        113        ROPE_ADD                                      1  ~76     ~76, ~73
        114        ROPE_ADD                                      2  ~76     ~76, '%27%3E'
        115        FETCH_DIM_R                                      ~74     !1, 0
        116        ROPE_ADD                                      3  ~76     ~76, ~74
        117        ROPE_END                                      4  ~75     ~76, '%3C%2Fa%3E+'
        118        SEND_VAL                                                 ~75
        119        SEND_VAR                                                 !16
        120        DO_ICALL                                         $79     
        121        ASSIGN                                                   !16, $79
   83   122    >   INIT_FCALL                                               'preg_match'
        123        SEND_VAR                                                 !18
        124        SEND_VAR                                                 !16
        125        SEND_REF                                                 !20
        126        DO_ICALL                                         $81     
        127      > JMPZ                                                     $81, ->147
   86   128    >   INIT_FCALL                                               'preg_replace'
        129        SEND_VAR                                                 !18
        130        ROPE_INIT                                     5  ~85     '%3Ca+href%3D%27https%3A%2F%2Ftwitter.com%2Fsearch%3Fq%3D'
        131        FETCH_DIM_R                                      ~82     !20, 0
        132        ROPE_ADD                                      1  ~85     ~85, ~82
        133        ROPE_ADD                                      2  ~85     ~85, '%27%3E'
        134        FETCH_DIM_R                                      ~83     !20, 0
        135        ROPE_ADD                                      3  ~85     ~85, ~83
        136        ROPE_END                                      4  ~84     ~85, '%3C%2Fa%3E+'
        137        SEND_VAL                                                 ~84
        138        SEND_VAR                                                 !16
        139        DO_ICALL                                         $88     
        140        ASSIGN                                                   !16, $88
   89   141        INIT_FCALL                                               'str_replace'
        142        SEND_VAL                                                 '%2Fsearch%3Fq%3D%23'
        143        SEND_VAL                                                 '%2Fsearch%3Fq%3D%2523'
        144        SEND_VAR                                                 !16
        145        DO_ICALL                                         $90     
        146        ASSIGN                                                   !16, $90
   93   147    >   INIT_FCALL                                               'preg_match'
        148        SEND_VAR                                                 !19
        149        SEND_VAR                                                 !16
        150        SEND_REF                                                 !21
        151        DO_ICALL                                         $92     
        152      > JMPZ                                                     $92, ->159
   95   153    >   INIT_FCALL                                               'preg_replace'
        154        SEND_VAL                                                 '%2F%40%28%5Ba-z_0-9%5D%2B%29%2Fi'
        155        SEND_VAL                                                 '%3Ca+href%3D%27http%3A%2F%2Ftwitter.com%2F%241%27%3E%240%3C%2Fa%3E'
        156        SEND_VAR                                                 !16
        157        DO_ICALL                                         $93     
        158        ASSIGN                                                   !16, $93
  100   159    >   CONCAT                                           ~95     '%3Cli%3E', !16
        160        CONCAT                                           ~96     ~95, '%3C%2Fli%3E'
        161        ECHO                                                     ~96
   71   162      > JMP                                                      ->100
        163    >   FE_FREE                                                  $69
  102   164        ECHO                                                     '%3C%2Ful%3E'
  103   165      > RETURN                                                   1

Function buildbasestring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 19
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/u52fp
function name:  buildBaseString
number of ops:  36
compiled vars:  !0 = $baseURI, !1 = $method, !2 = $params, !3 = $r, !4 = $value, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    5     3        ASSIGN                                                   !3, <array>
    6     4        INIT_FCALL                                               'ksort'
          5        SEND_REF                                                 !2
          6        DO_ICALL                                                 
    7     7      > FE_RESET_R                                       $8      !2, ->19
          8    > > FE_FETCH_R                                       ~9      $8, !4, ->19
          9    >   ASSIGN                                                   !5, ~9
    8    10        NOP                                                      
         11        FAST_CONCAT                                      ~12     !5, '%3D'
         12        INIT_FCALL                                               'rawurlencode'
         13        SEND_VAR                                                 !4
         14        DO_ICALL                                         $13     
         15        CONCAT                                           ~14     ~12, $13
         16        ASSIGN_DIM                                               !3
         17        OP_DATA                                                  ~14
    7    18      > JMP                                                      ->8
         19    >   FE_FREE                                                  $8
   10    20        CONCAT                                           ~15     !1, '%26'
         21        INIT_FCALL                                               'rawurlencode'
         22        SEND_VAR                                                 !0
         23        DO_ICALL                                         $16     
         24        CONCAT                                           ~17     ~15, $16
         25        CONCAT                                           ~18     ~17, '%26'
         26        INIT_FCALL                                               'rawurlencode'
         27        INIT_FCALL                                               'implode'
         28        SEND_VAL                                                 '%26'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $19     
         31        SEND_VAR                                                 $19
         32        DO_ICALL                                         $20     
         33        CONCAT                                           ~21     ~18, $20
         34      > RETURN                                                   ~21
   11    35*     > RETURN                                                   null

End of function buildbasestring

Function buildauthorizationheader:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/u52fp
function name:  buildAuthorizationHeader
number of ops:  24
compiled vars:  !0 = $oauth, !1 = $r, !2 = $values, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        ASSIGN                                                   !1, 'Authorization%3A+OAuth+'
   15     2        ASSIGN                                                   !2, <array>
   16     3      > FE_RESET_R                                       $7      !0, ->16
          4    > > FE_FETCH_R                                       ~8      $7, !3, ->16
          5    >   ASSIGN                                                   !4, ~8
   17     6        NOP                                                      
          7        FAST_CONCAT                                      ~11     !4, '%3D%22'
          8        INIT_FCALL                                               'rawurlencode'
          9        SEND_VAR                                                 !3
         10        DO_ICALL                                         $12     
         11        CONCAT                                           ~13     ~11, $12
         12        CONCAT                                           ~14     ~13, '%22'
         13        ASSIGN_DIM                                               !2
         14        OP_DATA                                                  ~14
   16    15      > JMP                                                      ->4
         16    >   FE_FREE                                                  $7
   18    17        INIT_FCALL                                               'implode'
         18        SEND_VAL                                                 '%2C+'
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $15     
         21        ASSIGN_OP                                     8          !1, $15
   19    22      > RETURN                                                   !1
   20    23*     > RETURN                                                   null

End of function buildauthorizationheader

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.33 ms | 1419 KiB | 35 Q