Jump to content


Photo

Edit Text File


  • Please log in to reply
7 replies to this topic

#1 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 21 March 2006 - 01:44 PM

Good morning php experts,

I have a text file called clients.txt. This file contains admins for my game servers. I also have a database which holds all of my clan members with all info I need.

What I want to do is this:

1. open up the clients.txt file
2. search for "players". this is the second line of the text file
3. insert my desired text after this line and put the rest of the text back

Any help would be cool guys

Thanks

Ray

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 21 March 2006 - 08:48 PM

Man you guys have been failing me lately :)

I got it all set.

Ray

#3 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 21 March 2006 - 10:34 PM

[!--quoteo(post=357087:date=Mar 21 2006, 03:48 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 21 2006, 03:48 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Man you guys have been failing me lately[/quote]

Sorry to hear you had to learn something with out us.

I've noticed that the number of people on the site has declined dramatically the last few days. It's 530 pm here now, and usually when I look at the number of people viewing the form it's 150+ this time of day. Right now it's 16.

I hate to attribute it to the new ads, but that's the only really noticeable change that's taken place.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 March 2006 - 12:09 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]I hate to attribute it to the new ads, but that's the only really noticeable change that's taken place.[/quote]
It's not so much the new ads, but they process that is used to get them on the page. It's causing a noticable delay when displaying the pages and warnings that scripts are taking too long. Enough of them and people stop coming. And the occasional problems posting code doesn't help either.

Ken

#5 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 22 March 2006 - 01:42 PM

I am just busting your chops guys!! I have learned so much from you guys here, ads, or no ads I will continue to come and help people out.

It seems like I help people alot more than I ask lately, which is a great thing. I enjoy helping people out cause I will not forget I was there once and always got help here. I have designed over 5 sites, all with php, and have not had something not work that I was trying to do. Of course a little java in the mix helps out. But they range from my Clan site to a few Database driven intranet sites for a couple local companies. One, my site is running their entire invoice and quoting system right from their browser. Enough bragging LOL let me go help some peeps out

Later all

Ray

#6 Grande

Grande
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 22 March 2006 - 03:25 PM

[!--quoteo(post=357087:date=Mar 21 2006, 09:48 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 21 2006, 09:48 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Man you guys have been failing me lately :)

I got it all set.

Ray
[/quote]

Could you post your solution for your problem,
seems like an interesting thing that I can probably use.
Thx!
Grande


#7 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 22 March 2006 - 06:37 PM

Well it was not really a search and replace type thing. Since I needed to add some data and I could add it anywhere I wanted as long as it was not in the middle of something else, I used this.

// Run Query to get new data
$sql = "SELECT handle, steamid FROM recruit_app WHERE handle = 'JohnnyBravo'";
  $res = mysql_query($sql) or die (mysql_error());
    while ($r = mysql_fetch_array($res)){
      $new = "     \"".$r['handle']."\"\n     {\n      \"name\" \"".$r['handle']."\"\n      \"steam\" \"".$r['steamid']."\"\n      \"admingroups\" \"Recruits\"\n      \"immunitygroups\" \"Recruits\"\n     }\n";
      }
      echo "$new<br /><br />";
$top = file_get_contents($myTextFile, False, NULL, 0, 33);
$bottom = file_get_contents($myTextFile, False, NULL, 34);
$toptext = stripslashes($top);
$bottomtext = stripslashes($bottom);
$newtext = ''.$toptext.''.$new.''.$bottomtext.'';
echo nl2br($newtext);

$inputString = $newtext;

Ray

#8 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 22 March 2006 - 10:32 PM

[!--quoteo(post=357313:date=Mar 22 2006, 10:25 AM:name=Grande)--][div class=\'quotetop\']QUOTE(Grande @ Mar 22 2006, 10:25 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
seems like an interesting thing that I can probably use.
[/quote]

A long time ago I posted some stuff about working with text files...a mini-tutorial if you will.

[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=63496\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=63496[/a]

It was closed almost immeidatly by toplay...I don't think he appreciated the post very much for some reason.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users