Advertisement
jargon

Roe Collector Card Game (mk45CARDS)

Sep 30th, 2021
1,521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.90 KB | None | 0 0
  1. <?php
  2.  
  3. include_once( 'go.php' );
  4. $me = me_shorthand( $_SERVER['SCRIPT_NAME'] );
  5.  
  6. // top of page (title)
  7. echo '<html><head><title>Roe XAMPP Builder (mk'.
  8. ( !is_null( $me ) ? ' '. $me['mk'] : '').
  9. ( !is_null( $me ) ? ' '. $me['me'] : '').
  10. ')</title><style>'. nen_css() . '</style></head><body>';
  11.  
  12. // copyright header
  13. echo '<table style="width:100%;text-align:top;"><tr><th colspan="2">
  14. <span style="alignment:center center;font-size:170%;">Roe Collector Card Game</span><br><span style="alignment:center center;font-size:120%;">Copyright 1997, 2021 Tim Keal</span><br><span style="alignment:center center;font-size:100%;">mk'. $me['mk']. $me['me']. '</span></th></tr>';
  15.  
  16. // perform regex upon data from table of contents
  17. if( !is_null( $me ) ){
  18.     trk_echo2('result', regex_toc( $me['mk'], $me['me'] ));
  19. }
  20.  
  21. // bottom of page
  22. echo '</body></html>';
  23.    
  24. function regex_toc( $mk, $me )
  25. {
  26.     global $nen;
  27.    
  28.     // table of contents filename pattern
  29.     $toc_index = 0;
  30.     $toc_pattern = '/cards\.dat/';
  31.    
  32.     $toc = fasttoc( 'cards src data', array( '.dat' ) );
  33.  
  34.     $toc_result = '';
  35.  
  36.     $card_replace = "$0\n";
  37.    
  38.     $toc_lines = array();
  39.    
  40.     $result = '';
  41.    
  42.     // loop through toc
  43.     while(
  44.         ($toc_index > count( $toc ) - 1)?false:preg_match(
  45.         $toc_pattern,
  46.         $toc[ $toc_index ],
  47.         $toc_matches
  48.         )
  49.     )
  50.     {      
  51.         // echo current toc filename
  52.         echo '<h3>'. htmlentities( $toc[ $toc_index ] ). '</h3>';
  53.                
  54.         // load current document by toc index into page memory
  55.         $page = file_get_contents( $nen[ 'root' ]. 'cards src data/'. $toc[ $toc_index ] );
  56.        
  57.         // echo currently loaded document
  58.         echo str_replace( "\r\n", '<br>'."\r\n", htmlentities( $page ) );
  59.        
  60.         $result .= regex_cards( $page );
  61.        
  62.         // increment one table of contents file higher
  63.         $toc_index++;      
  64.        
  65.     }
  66.    
  67.     return $result;
  68.    
  69. }
  70. function regex_cards( $page = '' )
  71. {
  72.     global $nen;
  73.     $result = '';
  74.    
  75.     //load card regular expression
  76.    
  77.     $card_pattern ='/CASE "(?<cardname>_{4}|[a-z][a-z0-9_]{3})"(?:\s*+(?!CASE).*\n)*/m';
  78.     $card_pattern2 = file_get_contents( $nen[ 'root' ]. 'pcre/card data.pattern.pcre' );
  79.     if( $card_pattern !== $card_pattern2 )
  80.     {
  81.         $card_pattern = $card_pattern2;
  82.     }
  83.     unset( $card_pattern2 );
  84.    
  85.     // assign replacement (unused)
  86.     $card_replace = "$0\n";
  87.    
  88.     // create desination folder if it does not exist
  89.     if( !is_dir( $nen[ 'root' ]. 'cards out data' ) )
  90.     {
  91.         mkdir ( $nen[ 'root' ]. 'cards out data' );
  92.     }
  93.    
  94.     // perform current page data regex
  95.    
  96.     if(
  97.         preg_match_all(
  98.         $card_pattern,
  99.         $page,
  100.         $card_matches
  101.         )
  102.     )  
  103.     {
  104.         //foreach($card_matches as $card_key => $card_value )
  105.         //{
  106.             trk_echo2( 'card', array( 'cardname' => $card_matches[ 'cardname' ], 'card_value' => $card_matches[ 0 ] ) );
  107.            
  108.             // save creation card collection to file
  109.             file_put_contents( $nen[ 'root' ]. 'cards out data/'. $card_matches[ 'cardname' ][ 0 ]. '.dat', $card_matches[ 0 ][ 0 ] );
  110.         //}
  111.        
  112.     }
  113.            
  114.     return $result;
  115.    
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement