Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once( 'go.php' );
- $me = me_shorthand( $_SERVER['SCRIPT_NAME'] );
- // top of page (title)
- echo '<html><head><title>Roe XAMPP Builder (mk'.
- ( !is_null( $me ) ? ' '. $me['mk'] : '').
- ( !is_null( $me ) ? ' '. $me['me'] : '').
- ')</title><style>'. nen_css() . '</style></head><body>';
- // copyright header
- echo '<table style="width:100%;text-align:top;"><tr><th colspan="2">
- <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>';
- // perform regex upon data from table of contents
- if( !is_null( $me ) ){
- trk_echo2('result', regex_toc( $me['mk'], $me['me'] ));
- }
- // bottom of page
- echo '</body></html>';
- function regex_toc( $mk, $me )
- {
- global $nen;
- // table of contents filename pattern
- $toc_index = 0;
- $toc_pattern = '/cards\.dat/';
- $toc = fasttoc( 'cards src data', array( '.dat' ) );
- $toc_result = '';
- $card_replace = "$0\n";
- $toc_lines = array();
- $result = '';
- // loop through toc
- while(
- ($toc_index > count( $toc ) - 1)?false:preg_match(
- $toc_pattern,
- $toc[ $toc_index ],
- $toc_matches
- )
- )
- {
- // echo current toc filename
- echo '<h3>'. htmlentities( $toc[ $toc_index ] ). '</h3>';
- // load current document by toc index into page memory
- $page = file_get_contents( $nen[ 'root' ]. 'cards src data/'. $toc[ $toc_index ] );
- // echo currently loaded document
- echo str_replace( "\r\n", '<br>'."\r\n", htmlentities( $page ) );
- $result .= regex_cards( $page );
- // increment one table of contents file higher
- $toc_index++;
- }
- return $result;
- }
- function regex_cards( $page = '' )
- {
- global $nen;
- $result = '';
- //load card regular expression
- $card_pattern ='/CASE "(?<cardname>_{4}|[a-z][a-z0-9_]{3})"(?:\s*+(?!CASE).*\n)*/m';
- $card_pattern2 = file_get_contents( $nen[ 'root' ]. 'pcre/card data.pattern.pcre' );
- if( $card_pattern !== $card_pattern2 )
- {
- $card_pattern = $card_pattern2;
- }
- unset( $card_pattern2 );
- // assign replacement (unused)
- $card_replace = "$0\n";
- // create desination folder if it does not exist
- if( !is_dir( $nen[ 'root' ]. 'cards out data' ) )
- {
- mkdir ( $nen[ 'root' ]. 'cards out data' );
- }
- // perform current page data regex
- if(
- preg_match_all(
- $card_pattern,
- $page,
- $card_matches
- )
- )
- {
- //foreach($card_matches as $card_key => $card_value )
- //{
- trk_echo2( 'card', array( 'cardname' => $card_matches[ 'cardname' ], 'card_value' => $card_matches[ 0 ] ) );
- // save creation card collection to file
- file_put_contents( $nen[ 'root' ]. 'cards out data/'. $card_matches[ 'cardname' ][ 0 ]. '.dat', $card_matches[ 0 ][ 0 ] );
- //}
- }
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement