I'm trying to get the value of if condition that make the condition TRUE, I have the following example:
(code.php)
<?php
$a = 'Data';
if(substr($a, 0, strlen("<SCRIPT"))=== "<SCRIPT" ) {
echo TRUE;
}
?>
in the above example, I'm trying to get the value <SCRIPT without double quotations. I tried some steps, but it still get the double quotation with the value (<SCRIPT). I plan then to assign the value <SCRIPT to another variable. Next code shows my code to get the result, where it still not working properly:
(test.php)
<?php
$file = file_get_contents("code.php"); // Code.php the page that include the if condition
$lines = explode("\n", $file); // get each line of source code and store it in array ($lines)
function sanitize_recursive($s) {
if (is_array($s)) {
return(array_map('sanitize_recursive', $s));
} else {
return htmlspecialchars($s);
}
}
foreach ($lines as $key => &$value) {
if(strpos($value, 'if') != false) // check if the line have if statement
{
if((strpos($value, '==')) !== false ) // check if the line compare two values
{
$pos1 = strpos($value, '==') + 2; // get the existence position of '==' + 2
$pos2 = strrpos($value, ')'); // get the position of last ) in the line
$startIndex = min($pos1, $pos2);
$length = abs($pos1 - $pos2);
$between = sanitize_recursive(substr($value, $startIndex, $length)); // get the value between 2 position + sanitize the tag to show it
echo $between; // will print: "<SCRIPT" with double quotation
}
}
}
?>
I want a way to print the value that make the if condition be TRUE, which is (
Thank you
Aucun commentaire:
Enregistrer un commentaire