Substr

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Lil' Neo C
Forum Newbie
Posts: 2
Joined: Tue Nov 04, 2003 7:13 pm

Substr

Post 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.
Lil' Neo C
Forum Newbie
Posts: 2
Joined: Tue Nov 04, 2003 7:13 pm

Post by Lil' Neo C »

I solved it without your help 8)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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)?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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).
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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. ;)
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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: :?
Post Reply