Hi, im a little stumped here. Im testing some scripts that I have wrote on my computer (wamp) but for some reason when using preg_match_all() nothing works! I even comment out most of the other code to see if something was interfering but no, still the same. Errors do show but not when using preg_match_all();
any help much appreciated;
<?php
define( "DB_USERNAME", "root" );
define( "DB_PASSWORD", "" );
define( "DB_SERVER", "localhost" );
define( "DB_NAME", "s_framework" );
$CON = mysql_connect( DB_SERVER, DB_USERNAME, DB_PASSWORD ) or die ( mysql_error() );
$DB = mysql_select_db( DB_NAME, $CON );
$query = "SELECT * FROM `files` ORDER BY ID";
$query = mysql_query( $query, $CON ) or die ( mysql_error() );
$remove_comments = true;
$remove_white_space = false;
$new_folder = 'new_encrypt/';
$encryption_code = 'foobar';
$path_array = array();
$user_defined_functions = array('name' => array(), 'encode' => array());
$user_defined_variables = array('name' => array(), 'encode' => array());
$user_defined_constants = array('name' => array(), 'encode' => array());
if( ! file_exists( $new_folder ) ) {
mkdir( $new_folder, 0700);
}
while( $rows = mysql_fetch_array( $query ) ){
$name = $rows['NAME'];
$location = $rows['LOCATION'];
$path = $location . $name;
$path_array['path'][] = $path;
$path_array['name'][] = $name;
$path_array['location'][] = $location;
$lines = file($path);
$data = implode("", $lines);
preg_match_all("#<\?php*((?!\?>).)*\?>#Us", $data, $matches);
print_r($matches);
#foreach ($lines as $line_num => $line) {
# if( preg_match( "#function\s+([^\s\(]+)\s?\([^\)]+\)#is", $line, $match ) ){
# if( ! in_array( $match[1], $user_defined_functions['name'] ) ) {
# $user_defined_functions['name'][] = $match[1];
# $user_defined_functions['encode'][] = "v" . md5($match[1].$encryption_code);
# }
# }
# if( preg_match( '#\$([a-zA-Z_][a-zA-Z0-9_]*)#is', $line, $match ) ){
# if( ! in_array( $match[1], $user_defined_variables['name'] ) ) {
# $user_defined_variables['name'][] = $match[1];
# $user_defined_variables['encode'][] = "v" . md5($match[1].$encryption_code);
# }
# }
# if( preg_match( '#define\s?\(\s?[\'\"]([^\s\"\']+)#is', $line, $match ) ){
# if( ! in_array( $match[1], $user_defined_constants['name'] ) ) {
# $user_defined_constants['name'][] = $match[1];
# $user_defined_constants['encode'][] = "v" . md5($match[1].$encryption_code);
# }
# }
#}
}
#foreach( $path_array['location'] as $key => $folder ) {
# if( ! file_exists( $new_folder . $folder ) ) {
# mkdir( $new_folder . ltrim($folder, "./"), 0700);
# }
# $lines = file($path_array['path'][$key]);
# $data = implode("", $lines);
# foreach( $user_defined_functions['name'] as $key2 => $f_name ) {
# $data = str_replace( $f_name, $user_defined_functions['encode'][$key2], $data );
# }
# foreach( $user_defined_variables['name'] as $key2 => $f_name ) {
# $data = preg_replace( '#\$' . $f_name . "(\;|\s|\,|\[|-|\))#", '$' . $user_defined_variables['encode'][$key2] . "$1", $data );
# }
# foreach( $user_defined_constants['name'] as $key2 => $f_name ) {
# $data = preg_replace( "#([\"\']\s?\.\s?)" . $f_name . "#", "$1" . $user_defined_constants['encode'][$key2], $data );
# }
#
# $fp = fopen( $new_folder . ltrim($folder, "./") . $path_array['name'][$key], 'w');
# fwrite($fp, $data);
# fclose($fp);
#
#}
?>