Oct 04 2006
New BellaBuffs blanklinefix Function
I’ve modified the BellaBuffs (and as such, BellaBook) function which removes whitespace from the end of lines so that it now removes empty lines too (which it didn’t properly before). This solves the problem caused by members that have been approved all at once causing blank lines and thus undefined offset errors. Until I can upload the fixed version (tonight), open your copy of config.php and find:
// blank line fix stolen from bellabook
function blanklinefix($inputfile) {
$content = file_get_contents($inputfile);
if($content != FALSE) {
$fixed = ltrim(rtrim($content));
$handle = fopen($inputfile, "w+");
fwrite($handle, $fixed);
fseek($handle, 0);
}
}
REPLACE it with:
function blanklinefix($inputfile) {
$content = file($inputfile);
if (count($content) > 0) {
$content = array_diff(array_diff($content, array("")), array("n"));
$newContent = array();
foreach ($content as $line) {
$newContent[] = trim($line);
}
$newContent = implode("n", $newContent);
$handle = fopen($inputfile, "w+");
fwrite($handle, $newContent);
fseek($handle, 0);
}
}
If anyone could tell me why Made some further changes, trim() doesn’t seem to work and I’m having to rely on the two ‘side’ trims to achieve that affect I’d greatly appreciate it!trim() now works and I’ve corrected a couple of stupid mistakes that I should have spotted originally.
Warning
This post is over 6 months old. This means that, despite my best intentions, it may no longer be accurate. Age, motherhood, experience, loss... these things have all changed me from when this blog was started back in the heady (ha) days of my youth.
As much as I would like to go back and edit 10 years of archives to provide an insight into the 'me' of now — to update coding snippets and revise website advice — it would probably take years to do so (by which point I'd have to start again!) This would defeat the point of keeping these archives anyway.
Please take these posts for what they are: a brief look into my past, my history, my journey.
20 Responses so far
-
Hey there Jem! I’m a long-time reader, first-time commenter. =P I just wanted to say that you rock so freakin’ much for always taking care to correct your scripts (and others) and make sure they’re top security for users out there. So, this is just a little Thanks from me.
-
You have an open code tag in your entry. Love the new layout!
-
Speaking of BellaBuffs … I downloaded it the other day and a few hours ago I gave the convert-from-enth script a try – I received the following error: “Undefined index in “…” on line 30″ on each line/for each member. I figured you might want to know and take a look at that :)
-
:) Thanks for the fix, Jem! You’re a champ!
-
Oh great. :) I had been wondering what was causing this and I was too lazy to email you. P.S. Oh, your link colors changed. :whistle:
-
Thanks Jem, I had noticed this while I was approving some members, but I had chalked it up to my incompetence at modifying PHP… can’t wait to give this a try, though!
-
Thanks Jem! I’m setting Bellabuffs up to use with my new fanlisting so now I can implement the change before uploading it all :)
-
the array_diff looks so redundant..i could be wrong but what about. function trimmit(&$value){ $value = trim($value); } array_walk($content, ‘trimmit’);
-
Ooh Jem, I forgot to say I really like the new layout (and favicon) but in IE the logo moves up and down rather than staying fixed (like in FF). I only noticed it now because I normally don’t use IE ;)
-
Hey Jem – I’m not a big user of PHP but first glance i’m wondering why if (count($inputfile) > 0) { is used and not if (count($content) > 0) {? $content is an array of lines from file() yeah? You said you’re just removing whitespace from the end of lines – wont rtrim() alone be alright, Jem?
-
Should have known you already knew about the fixed background problem in IE. Actually come to think of it I should have known it’s IE fault hehe.
-
Hi Jem! Thanks so much for the fix! I’ll let my friends know about this one (they’ve been really loving Bellabuffs since I introduced them to the script :) ). I know this is off topic, but have you ever considered opening a site directory of fanlistings that use Bellabuffs? I know the question is kind of redundant, but this is just out of curiosity. Or maybe a site similar already exists and I just didn’t know about it… :) Thanks again!
-
Thanks for trying to fix all errors in BellaBuffs, Jem! ILY xD
-
Adrianne: the BellaBuffs fanlisting has a small directory which I hope to see growing. :)









