3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Make sure SimplePie is included. You may need to change this to match the location of autoloader.php // For 1.0-1.2: #require_once('../simplepie.inc'); // For 1.3+: require_once __DIR__ . DIRECTORY_SEPARATOR . 'autoloader.php'; // We'll process this feed with all of the default options. $feed = new SimplePie(); // Set which feed to process. // Single feed $feed = new SimplePie(); $feed->set_feed_url(array('http://www.corex-fitness.com/blog/feed/')); $feed->enable_order_by_date(false); //$feed->set_cache_location(basename(__DIR__) . '/cache'); $feed->init(); // Run SimplePie. $feed->init(); // This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it). $feed->handle_content_type(); // Let's begin our XHTML webpage code. The DOCTYPE is supposed to be the very first thing, so we'll keep it on the same line as the closing-PHP tag. //Shorten the description. function shorten($string, $length) { // By default, an ellipsis will be appended to the end of the text. $suffix = '&hellip;'; // Convert 'smart' punctuation to 'dumb' punctuation, strip the HTML tags, // and convert all tabs and line-break characters to single spaces. $short_desc = trim(str_replace(array("\r","\n", "\t"), ' ', strip_tags($string))); // Cut the string to the requested length, and strip any extraneous spaces // from the beginning and end. $desc = trim(substr($short_desc, 0, $length)); // Find out what the last displayed character is in the shortened string $lastchar = substr($desc, -1, 1); // If the last character is a period, an exclamation point, or a question // mark, clear out the appended text. if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix=''; // Append the text. $desc .= $suffix; // Send the new description back to the page. return $desc; } function get_first_image_url($html) { if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) { return $matches[1]; } //else return 'url_of_default_image_if_post_has_no_img_tags.jpg'; } ?> <?php /* Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop. */ foreach ($feed->get_items(0, 1) as $item): ?> <div class=" col-1"> <div class="block block-list"> <div class="block-title"><strong> <span>Blog</span> </strong></div> <div class="block-content"><?php echo '<img src="' .get_first_image_url($item->get_content()). '"/>'; ?> <div class="content-title"><a href="<?php echo $item->get_permalink(); ?>" target="_blank"><?php echo $item->get_title(); ?></a></div> <p><?php echo shorten($item->get_description(), 150); ?></p> <p>Written on <?php echo $item->get_date('jS F Y'); ?></p> <p><a href="<?php echo $item->get_permalink(); ?>" target="_blank">Read More</a></p> </div> </div> </div> <?php endforeach; ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 62
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 62
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
filename:       /in/8LCTK
function name:  (null)
number of ops:  64
compiled vars:  !0 = $feed, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   INCLUDE_OR_EVAL                                          '%2Fin%2Fautoloader.php', REQUIRE_ONCE
   11     1        NEW                                              $3      'SimplePie'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   15     4        NEW                                              $6      'SimplePie'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $6
   16     7        INIT_METHOD_CALL                                         !0, 'set_feed_url'
          8        SEND_VAL_EX                                              <array>
          9        DO_FCALL                                      0          
   17    10        INIT_METHOD_CALL                                         !0, 'enable_order_by_date'
         11        SEND_VAL_EX                                              <false>
         12        DO_FCALL                                      0          
   19    13        INIT_METHOD_CALL                                         !0, 'init'
         14        DO_FCALL                                      0          
   22    15        INIT_METHOD_CALL                                         !0, 'init'
         16        DO_FCALL                                      0          
   25    17        INIT_METHOD_CALL                                         !0, 'handle_content_type'
         18        DO_FCALL                                      0          
   64    19        ECHO                                                     '%0A'
   69    20        INIT_METHOD_CALL                                         !0, 'get_items'
         21        SEND_VAL_EX                                              0
         22        SEND_VAL_EX                                              1
         23        DO_FCALL                                      0  $14     
         24      > FE_RESET_R                                       $15     $14, ->62
         25    > > FE_FETCH_R                                               $15, !1, ->62
   71    26    >   ECHO                                                     '%0A%09%3Cdiv+class%3D%22+col-1%22%3E%0A%3Cdiv+class%3D%22block+block-list%22%3E%0A%3Cdiv+class%3D%22block-title%22%3E%3Cstrong%3E+%3Cspan%3EBlog%3C%2Fspan%3E+%3C%2Fstrong%3E%3C%2Fdiv%3E%0A%3Cdiv+class%3D%22block-content%22%3E'
   75    27        INIT_FCALL                                               'get_first_image_url'
         28        INIT_METHOD_CALL                                         !1, 'get_content'
         29        DO_FCALL                                      0  $16     
         30        SEND_VAR                                                 $16
         31        DO_FCALL                                      0  $17     
         32        CONCAT                                           ~18     '%3Cimg+src%3D%22', $17
         33        CONCAT                                           ~19     ~18, '%22%2F%3E'
         34        ECHO                                                     ~19
   76    35        ECHO                                                     '%3Cdiv+class%3D%22content-title%22%3E%3Ca+href%3D%22'
         36        INIT_METHOD_CALL                                         !1, 'get_permalink'
         37        DO_FCALL                                      0  $20     
         38        ECHO                                                     $20
         39        ECHO                                                     '%22+target%3D%22_blank%22%3E'
         40        INIT_METHOD_CALL                                         !1, 'get_title'
         41        DO_FCALL                                      0  $21     
         42        ECHO                                                     $21
         43        ECHO                                                     '%3C%2Fa%3E%3C%2Fdiv%3E%0A%3Cp%3E'
   77    44        INIT_FCALL                                               'shorten'
         45        INIT_METHOD_CALL                                         !1, 'get_description'
         46        DO_FCALL                                      0  $22     
         47        SEND_VAR                                                 $22
         48        SEND_VAL                                                 150
         49        DO_FCALL                                      0  $23     
         50        ECHO                                                     $23
         51        ECHO                                                     '%3C%2Fp%3E%0A%3Cp%3EWritten+on+'
   78    52        INIT_METHOD_CALL                                         !1, 'get_date'
         53        SEND_VAL_EX                                              'jS+F+Y'
         54        DO_FCALL                                      0  $24     
         55        ECHO                                                     $24
         56        ECHO                                                     '%3C%2Fp%3E%0A%3Cp%3E%3Ca+href%3D%22'
   79    57        INIT_METHOD_CALL                                         !1, 'get_permalink'
         58        DO_FCALL                                      0  $25     
         59        ECHO                                                     $25
         60        ECHO                                                     '%22+target%3D%22_blank%22%3ERead+More%3C%2Fa%3E%3C%2Fp%3E%0A%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%0A'
   69    61      > JMP                                                      ->25
         62    >   FE_FREE                                                  $15
   84    63      > RETURN                                                   1

Function shorten:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
2 jumps found. (Code = 47) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
Branch analysis from position: 37
Branch analysis from position: 34
filename:       /in/8LCTK
function name:  shorten
number of ops:  42
compiled vars:  !0 = $string, !1 = $length, !2 = $suffix, !3 = $short_desc, !4 = $desc, !5 = $lastchar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   33     2        ASSIGN                                                   !2, '%26hellip%3B'
   37     3        INIT_FCALL                                               'trim'
          4        INIT_FCALL                                               'str_replace'
          5        SEND_VAL                                                 <array>
          6        SEND_VAL                                                 '+'
          7        INIT_FCALL                                               'strip_tags'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $7      
         10        SEND_VAR                                                 $7
         11        DO_ICALL                                         $8      
         12        SEND_VAR                                                 $8
         13        DO_ICALL                                         $9      
         14        ASSIGN                                                   !3, $9
   41    15        INIT_FCALL                                               'trim'
         16        INIT_FCALL                                               'substr'
         17        SEND_VAR                                                 !3
         18        SEND_VAL                                                 0
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $11     
         21        SEND_VAR                                                 $11
         22        DO_ICALL                                         $12     
         23        ASSIGN                                                   !4, $12
   44    24        INIT_FCALL                                               'substr'
         25        SEND_VAR                                                 !4
         26        SEND_VAL                                                 -1
         27        SEND_VAL                                                 1
         28        DO_ICALL                                         $14     
         29        ASSIGN                                                   !5, $14
   48    30        IS_EQUAL                                         ~16     !5, '.'
         31      > JMPNZ_EX                                         ~16     ~16, ->34
         32    >   IS_EQUAL                                         ~17     !5, '%21'
         33        BOOL                                             ~16     ~17
         34    > > JMPNZ_EX                                         ~16     ~16, ->37
         35    >   IS_EQUAL                                         ~18     !5, '%3F'
         36        BOOL                                             ~16     ~18
         37    > > JMPZ                                                     ~16, ->39
         38    >   ASSIGN                                                   !2, ''
   51    39    >   ASSIGN_OP                                     8          !4, !2
   54    40      > RETURN                                                   !4
   55    41*     > RETURN                                                   null

End of function shorten

Function get_first_image_url:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8LCTK
function name:  get_first_image_url
number of ops:  10
compiled vars:  !0 = $html, !1 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   58     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%3Cimg.%2B%3Fsrc%3D%22%28.%2B%3F%29%22%2F'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->9
   59     7    >   FETCH_DIM_R                                      ~3      !1, 1
          8      > RETURN                                                   ~3
   62     9    > > RETURN                                                   null

End of function get_first_image_url

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.87 ms | 1411 KiB | 25 Q