Advertisement
jargon

This is lierally how preg_match_all is supposed to work

Oct 11th, 2021
1,830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2.  
  3. $page = <<< TXT
  4. CASE "grml"\r\n
  5.    prflidty$ = "Gremlin"\r\n
  6.    prflactn$ = "movebitepnch"\r\n
  7.    IF RND(1) > .2 THEN\r\n
  8.     prflactn$ = prflactn$ + "dggr"\r\n
  9.    END IF\r\n
  10.    prflgpic$ = "grml"\r\n
  11.    prflidty! = 4\r\n
  12.    prflhp! = 25\r\n
  13.    prflstr! = 90\r\n
  14.    prflspd! = 1\r\n
  15.    prflarmr! = 1\r\n
  16.    prflvalu! = 5\r\n
  17.    prflpirc! = 2\r\n
  18.    prfllv! = 1\r\n
  19.    prflhpmax! = 25\r\n
  20.    prflstrmax! = 90\r\n
  21. TXT;
  22.  
  23. echo gen_statsheet($page);
  24.  
  25. function gen_statsheet( $page = '' ) {
  26.     $return = '';
  27.  
  28.     $pattern =    '/(?:prfl(?<stat>idty|hp|str|spd|armr|valu|pirc|lv|hpmax|strmax|essmax|essspd)!) = (?<value>[.\d]+)/m';
  29.    
  30.     while( preg_match_all( $pattern, $page, $matches, PREG_UNMATCHED_AS_NULL ) )
  31.     {
  32.         if( !is_null( $matches[ 'stat' ] ) and !is_null( $matches[ 'value' ] ) )
  33.         {
  34.             $return .= '<p>'. $matches[ 'stat' ]. '='. $matches[ 'value' ]. '</p>';
  35.         }
  36.     }
  37.     return $return;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement