Page 1 of 1

Substr

Posted: Tue Nov 04, 2003 7:13 pm
by Lil' Neo C
$file = file($commentfile); // Reads file
$disstr = substr($file, 31, 6); // returns "FFFFFF"
echo $disstr;

in $commentfile all 15 lines of the *messages* from the shoutbox are stored.

$file opens that file and reads it right? It reads the first line? If not how can I make it so?

31 is when it gets right next to the FFFFFF which is the bgcolor. If i make file equal ...
<tr><td cellpadding=0 bgcolor=#FFFFFF>
It will work but doesnt display anything when i actually run it the real way.

Posted: Tue Nov 04, 2003 8:04 pm
by Lil' Neo C
I solved it without your help 8)

Posted: Wed Nov 05, 2003 2:14 am
by m3mn0n
You have a flat-file based shout box? Interesting...How is managing that compared to using a database based shoutbox (if you've used both of course)?

Posted: Wed Nov 05, 2003 2:26 am
by JAM
Not that different if I may add a personal comment. I did this when learning php, and it's really just read file into array, add a string to the array, re-write the file.

Each line contained string like: JAM|date|text that I exploded into usable variables, then echo them in a loop.

I made the str_len of the text <50 chars long, and the file automaticly discarded all lines above 20, so the textfile I used never got extremely large (main reason to use a db-shoutbox).

Posted: Wed Nov 05, 2003 2:31 am
by m3mn0n
Cool. I've not yet got around to building many flat-file applications, since I'm very keen on developing database management skills, but this sounds like a neat little weekend project I might do for some experience. ;)

Posted: Wed Nov 05, 2003 2:41 am
by Nay
Hey, long time no post here. I moved to another country and didn have any net access. I just installed RedHat so no mysql was compiled there. I was forced to use a flat file as a database - imagine the horror!

Anyhow, it's fairly simple. No more fopen() needed imho. Just use file(). Writing, fopen("file", "a+") and it works like a breeze :D. So don't be scared to explore.

I tried exploring XML but then that wasn't sooo successful :(

-Nay

Posted: Wed Nov 05, 2003 2:48 am
by twigletmac
Nay wrote:I tried exploring XML but then that wasn't sooo successful :(
Once you get your head around transforming XML with XSLT on the server-side it's like doing magic - boring XML document in, fantastic XHTML document out :).

Mac

Posted: Wed Nov 05, 2003 2:57 am
by Nay
ahhhh yes. the Mac has landed :D. There's a huge book store just 15 minutes away from my house (Kinokuniya, ever heard of it?). I go there everyday to read a book about XML and stuff and still a little :S. Just that every time i look at a XML parsing code in php (wow, 3 - 4 pages) and i just close the book and run away.

mMm...............i really need to stop doing that!

-Nay

Posted: Wed Nov 05, 2003 4:23 am
by m3mn0n
Yeah I got a 900 page book on PHP and XML that I'm just about half way done with reading. I have yet to do any execution or practice for the things i've read so far, thought it seems pretty practical and simple.

I've built so many things with a MySQL database since my newbie days that I've almost totally ignored other types of storage and data management methods. :oops: :?