Can someone tell me why the constant length isn't defined? I'm using glob to find and put all .txt files into an array then using for to loop through them echoing them out.
$filew = glob("/xampp/htdocs/new/*.txt");
for($n=0; $n<$filew.length; $n++) {
$filew['$n'] = substr($filew['$n'], 18, -4);
echo $filew['n'] . " ";
}
The error message indicates the problem lines in the second line, someone told me to put array content into quote marks but it hasn't worked. Thank you
PHP arrays don't have a length property. You should use count instead
$filew = glob("/xampp/htdocs/new/*.txt");
for($n = 0; $n < count($filew); $n++) {
$filew[$n] = substr($filew[$n], 18, -4);
echo $filew[$n] . " ";
}
You also have some errors in the way you are accessing your array. Using a single quote will cause the variable inside to not be rendered. Using $filew['$n'] will not give you a numeric value for $n. It will give a literal string with the value $n. Remove the single quotes should be just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With