Ok, the following code is a bit complex, but stay with me -
Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
$handle = file_get_contents('Test/1.per');
$find = '#(")(.*)(")#ui';
$replace = '"' . htmlentities('$2') . '"';
print preg_replace($find,$replace,$handle);
//echo '<pre>' . $handle . '</pre><br /><br /><br />';
$char_type = array(
" ",
"(",
")",
"{",
"}",
">",
"<",
"=",
".",
":",
";",
"\n",
"\t",
"\r",
"if",
);
$char_rep = array(
"SPACE",
"LEFT BRACKET",
"RIGHT BRACKET",
"LEFT PARENTHESIS",
"RIGHT PARENTHESIS",
"GREATER THAN",
"LESS THAN",
"EQUALS",
"PERIOD",
"COLON",
"SEMI COLON",
"NEW LINE",
"TAB",
"CARRIAGE RETURN",
"IF",
);
$export = array();
$compare = array();
$count1 = strlen($handle);
$count2 = count($char_type);
$count3;
for($i=0;$i<$count1;$i++) {
$r = substr($handle, $i, 1);
for($u=0;$u<$count2;$u++) {
if($r == $char_type[$u]) {
$count3 = strlen($stack);
if($count3 != 0) {
for($h=0;$h<$count3;$h++) {
$compare[$i - ($count3 - 0)] = 'UNKNOWN';
}
}
$compare[$i] = $char_rep[$u];
break;
} else {
if($stack == $char_type[$u]) {
$compare[$i] = $char_rep[$u];
$stack = "";
} else {
$stack = $stack . $r;
//$compare[$i] = 'UNKNOWN';
}
}
}
$export[$i] = $r;
//break;
}
for($z=0;$z<$count1;$z++) {
echo '[' . $export[$z] . '] - ';
echo $compare[$z] . '<br /><br />';
}
?>
</body>
</html>
Can you see what I'm trying to do?
It is picking up things like <, (, ;, etc.
But it isn't picking up the text if.
Also, on all the other text, it isn't printing UNDEFINED.
Any help?
p.s. If no one can figure it out, I'll go and plan it all out
Bookmarks