Code: Select all
Array
(
[0] => check_files/toplogo.png
[1] => check_files/topphp.png
[2] => check_files/shadow_tr.jpg
[3] => check_files/shadow_bl.jpg
[4] => check_files/shadow_br.jpg
)
Moderator: General Moderators
Code: Select all
Array
(
[0] => check_files/toplogo.png
[1] => check_files/topphp.png
[2] => check_files/shadow_tr.jpg
[3] => check_files/shadow_bl.jpg
[4] => check_files/shadow_br.jpg
)
Code: Select all
function array_alert($array){
echo '<script type="text/javascript">alert("'.implode('\n',array_map(@addslashes,$array)).'");</script>';
}Code: Select all
function jAlert($var){
if(is_array($var)) return print('<script type="text/javascript">alert("'.implode('\n',array_map(@addslashes,$var)).'");</script>');
return print('<script type="text/javascript">alert("'.addslashes($var).'");</script>');
}Code: Select all
function jAlert($var){
return '<script type="text/javascript">alert("'.addslashes(is_array($var) ? implode("\n", $var) : $var).'");</script>';
}a: Returning a print killed two birds with one stone - exiting the function as soon as the first print happened, AND providing a non-falsy return value that also happens to contain the output of the function.Jcart wrote:a simple one liner
You had a couple problems,Code: Select all
function jAlert($var){ return '<script type="text/javascript">alert("'.addslashes(is_array($var) ? implode("\n", $var) : $var).'");</script>'; }
a) whats the point of returning a print?
b) carriage needs to be processed in double quotes, else it's taken literally
c) your use of array_map isn't correct, you should consult the manual
array_map(@addslashes... triggers an error saying constant 'addslashes' not defined assuming 'addslashes' -- the string which, incidentally...is the correct usagec: As far as I can tell, my use of array_map() was correct, I just double checked the manual. Do you have any particular objection in mind to this usage?
Code: Select all
// consider: define('addslashes', 'unexceptedRedirection');
array_map(@addslashes, $array); // bad
array_map('addslashes', $array); // good