PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old July 17th, 2004, 11:14 PM
mochahete mochahete is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 mochahete User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Using str_replace() to read a text file and evaluate?

I am trying to write a script that will work the following way:

User uses a form to add a user to the site.
The script writes the value ($username) to a text file like this: $username|
$username2|
$username3|

I need a script that would prevent duplicate $username values to be written to the text file.

Should I be using str_replace? I am kind of new to PHP, but I learn pretty quickly

Please write back. Any help would be greatly appreciated

Reply With Quote
  #2  
Old July 18th, 2004, 05:09 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
If the usernames are on a line to themselves then scan through each line at a time comparing it to the new username. If you reach the end of the file then the username is not present. If they are delimited in some way then read the whole thing into a string and use the split function to chop it up. Then you can compare each entry in the array to the new username.

-KM-

Reply With Quote
  #3  
Old July 18th, 2004, 03:39 PM
mochahete mochahete is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 mochahete User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
KM,
Thanks for the response. Is there anyway that you could give me an example of how to do what you are stating here?

The text file which is storing the names has each username on a different line with the "|" character after it.

Thanks!!!

-mochahete

Reply With Quote
  #4  
Old July 18th, 2004, 09:58 PM
mochahete mochahete is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 mochahete User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have since been trying to figure out what KM meant. I have this:

function addtomainteachlist($teacher) {
$TheFile = "mainteacherlist.txt";
$fp = fopen("mainteacherlist.txt", 'a+');
chmod("mainteacherlist.txt", 0777);
$implode_me = array($teacher, "\n");
$noduplics = array_unique($implode_me);
$string = implode('|', $noduplics);
fwrite($fp, $string);
fclose($fp);
print ("Data Collected!<BR>\n");
}

Reply With Quote
  #5  
Old July 19th, 2004, 04:22 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
If they are stored one per line don't bother with the | since the newline will act as a delimiter. To check through the file open it using fopen in mode 'r' (read) and go through it one line at a time and compare.

Have a go at that and post your code up,

-KM-

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Using str_replace() to read a text file and evaluate?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway