Forum Moderators: coopster
Line 39 would be:
foreach ($widgets as $widget) {
in
$widgets = sort( file('widgets.txt') );
foreach ($widgets as $widget) {
rtrim($widget);
print('some HTML code here' . $widget . 'more code' );
}
I made a widgets.txt file containing nothing else but
widget
tegdiw
gdiwte
idgetw
dwtegi
and so on...
Sorry to be such an idiot.. :\ but I really have tried to find the answer on this forum, but without luck.
I'm also a newbie when it comes to php, although I've learned a LOT today!
So if you have the kindness, please help me one more time? :)
please?
Let's debug:
$widgets = sort( file('widgets.txt') );
print_r($widgets);
foreach ($widgets as $widget) {
rtrim($widget);
print('some HTML code here' . $widget . 'more code' );
}
Don't call yourself an idiot. You're just getting started and you will get better. Stick around here and it will happen faster :)
OK,
I tried this:
print_r($widgets);
I still get the error, but now it is a 1 above it..
like this:
1
Warning: Invalid argument supplied for foreach()
nothing wrong with the .txt file I made?
Is it supposed to look like this?
line1
line2
line3
line4
line5
and so on..
or this:
line1, line2, line3, line4?
Let's simplify it more:
<?php
error_reporting('E_ALL); //debug mode
$widgets = sort( file('widgets.txt') );
var_dump($widgets);
?>
You should either get an error or something like this:
array(10){
etc.
If you get array() then you should be able to run the original script. Go ahead and run this one and let us know the results.
[added]Yes, your text file is correct with each item on a line.[/added]
<?php$widgets = file('widgets.txt');
sort($widgets);
foreach ($widgets as $widget) {
rtrim($widget);
print('some HTML code here ' . $widget . ' more code<br>' );
}?>
Now it's sorting like it has never done anything else before!
And the best part is, I understand the code too! LOL
Thank you so much Birdman for pushing me in the right direction!