Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Ezilon Directory   I Sell Pagerank   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 07-09-2007, 07:04 AM   #1 (permalink)
Inactive
 
Join Date: 02-10-07
Posts: 9
iTrader: 0 / 0%
Latest Blog:
None

unbound is liked by many
PHP: checking problem

Hey! I've been working on this little chat thingy in php and got a problem now.
I have a textfile which has some text, like this:
a
b
c
d
e

every letter on its own row, and php code:
Code:
$all = file(myfile.txt); // do the checking for($i = 0; $i < count($all); $i++) { if($all[$i] == "b") { die("for good"); } }
but $all[$i] doesnt equal to b, eventhough it exists in file. So, what should I do to make it work?
Thanks in advance.
unbound is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 07-09-2007, 06:53 PM   #2 (permalink)
Contributing Member
 
stewart's Avatar
 
Join Date: 02-09-07
Location: New Orleans, LA
Posts: 168
iTrader: 0 / 0%
Latest Blog:
None

stewart is liked by many
Send a message via ICQ to stewart Send a message via AIM to stewart Send a message via MSN to stewart
Code:
<?php $file = implode('', file('mylist.txt')); for($i = 0; $i < strlen($file); $i++) { if($file[$i] == "b"){ die("for good."); } } ?>
That does what you are asking, but what are you trying to accomplish, just wondering ?

http://www.php.net/file
http://www.php.net/strlen
http://www.php.net/implode

Good luck,
- Stewart
link removed
__________________
stewart:howe
Web Developer & Programmer

www.CelerMedia.com

Last edited by chicgeek : 07-09-2007 at 07:42 PM.
stewart is offline  
Add Post to del.icio.us
Reply With Quote
Old 07-09-2007, 08:17 PM   #3 (permalink)
Contributing Member
 
Join Date: 06-29-07
Posts: 93
iTrader: 0 / 0%
Latest Blog:
None

roger_d is liked by many
Quote:
Originally Posted by unbound View Post
Hey! I've been working on this little chat thingy in php and got a problem now.
I have a textfile which has some text, like this:
a
b
c
d
e

every letter on its own row, and php code:
Code:
$all = file(myfile.txt); // do the checking for($i = 0; $i < count($all); $i++) { if($all[$i] == "b") { die("for good"); } }
but $all[$i] doesnt equal to b, eventhough it exists in file. So, what should I do to make it work?
Thanks in advance.
use trim to remove the newline.
if (trim($all[$i]) == "b") {
roger_d is offline  
Add Post to del.icio.us
Reply With Quote
Old 07-11-2007, 02:04 AM   #4 (permalink)
Inactive
 
Join Date: 02-10-07
Posts: 9
iTrader: 0 / 0%
Latest Blog:
None

unbound is liked by many
Thanks for your answers, got it working now.
What i'm trying to accomplish? I have this system that when user joins chat he writes hes name in a box and after that this script checks if it is already in use.
unbound is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Just checking John Scott Graphic Design Forum 11 09-06-2004 07:26 PM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 04:39 AM.
© Copyright 2008 V7 Inc