andytan91 Posted August 14, 2010 Share Posted August 14, 2010 Hello guys i used the eval function but it does not echo anything back in the while loop ..the $new_string function contains "preg_split("/\.\(.*\)\.\(.*\)/", $file);", same as $parts..i need some guidance, thanks! <?php //"$DOCUMENT_ROOT"."new/"; $current_dir = 'C:\xampp\htdocs\Audit_Reports'; //Put in second part, the directory - without a leading slash but with a trailing slash! $dir = opendir($current_dir); // Open the sucker $newArgument = $_POST[argument]; $newArgument1 = $_POST[argument1]; $string ='preg_split("/\.\(.*\)\.\(.*\)/", $file);'; $new_string = preg_replace("#\/\\\.\\\\\(\.\*\\\\\)#","/\.\\($newArgument\)",$string); $new_string = preg_replace("#\\\.\\\\\(\.\*\\\\\)#","\.\\($newArgument1\)", $new_string); echo ("<p><h1>List of Audit Reports:</h1></p><hr><br />"); while ($file = readdir($dir)) // while loop { $parts = preg_split("/\.\(CLIENT\)\.\(.*\)/", $file); // $part = eval($new_string); if (is_array($parts) && count($parts) > 1) { // does the dissected array have more than one part $extension = reset($parts); // set to we can see last file extension if ($extension == "Audit_Report" OR $extension == "audit_report") // is extension ext or EXT ? echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; // If so, echo it out else do nothing cos it's not what we want } } echo "<hr><br />"; closedir($dir); // Close the directory after we are done ?> The below codes are done in a while loop Result:ArrayArrayArrayArrayArrayArrayArrayArrayArrayArra yArrayArray $parts = preg_split("/\.\(A\)\.\(A\)/", $file); echo $parts; Result:No Output $part = eval($new_string); echo $part; Quote Link to comment https://forums.phpfreaks.com/topic/210686-eval-function-not-working-in-while-loop/ Share on other sites More sharing options...
.josh Posted August 14, 2010 Share Posted August 14, 2010 well the first thing I see wrong is $string ='preg_split("/\.\(.*\)\.\(.*\)/", $file);'; You are trying to use a variable inside single quotes. Single quotes do not parse variables, so you are assigning the literal string $file not the value of that variable. You either need to put it inside double quotes or else break out of your single quotes and concatenate Quote Link to comment https://forums.phpfreaks.com/topic/210686-eval-function-not-working-in-while-loop/#findComment-1099083 Share on other sites More sharing options...
andytan91 Posted August 14, 2010 Author Share Posted August 14, 2010 hmm i tried $string = "preg_split(\"/\.\(.*\)\.\(.*\)/\", \$file);"; if i do eval($string) and pass it to is_array and count function inside the while loop, theres no result still.. Quote Link to comment https://forums.phpfreaks.com/topic/210686-eval-function-not-working-in-while-loop/#findComment-1099093 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.