Current location: Hot Scripts Forums » Programming Languages » PHP » Match $var in text file ?

Match $var in text file ?

Reply
  #1  
Old 07-01-09, 01:06 PM
peuplarchie's Avatar
peuplarchie peuplarchie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 63
Thanks: 1
Thanked 0 Times in 0 Posts
Post Match $var in text file ?

Good day to you all,
stupid as it sound, all the thing that I have tried to match a variable into a text file and execute according to it result.


PHP Code:

$active 
"user_list.txt";
$pos strpos($active$_SESSION['username']);
if (
$pos === false) {
echo 
"<b id=\"userinfo\"><img src=\"enligne.png\" valign=\"bottom\" width=\"13px\"/></b>";
} else {
echo 
"<b id=\"userinfo\"><img src=\"horsligne.png\" valign=\"bottom\" width=\"13px\"/></b>";

Thanks !
Reply With Quote
  #2  
Old 07-01-09, 01:13 PM
Nico's Avatar
Nico Nico is online now
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,535
Thanks: 5
Thanked 17 Times in 16 Posts
You're matching it against the file name. You need to get the actual contents of the file: PHP: file_get_contents - Manual
Reply With Quote
  #3  
Old 07-01-09, 01:22 PM
peuplarchie's Avatar
peuplarchie peuplarchie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 63
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks, I knew it was a stupid thing I was not seeing cause of the level of sleep I had last night !
Reply With Quote
  #4  
Old 07-01-09, 03:03 PM
peuplarchie's Avatar
peuplarchie peuplarchie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 63
Thanks: 1
Thanked 0 Times in 0 Posts
Can I delete it too ?
Reply With Quote
  #5  
Old 07-01-09, 03:08 PM
Nico's Avatar
Nico Nico is online now
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,535
Thanks: 5
Thanked 17 Times in 16 Posts
Read the file contents with file_get_contents().
Replace the name with nothing, using str_replace().
Put the contents back to the file using file_put_contents().
Reply With Quote
  #6  
Old 07-01-09, 05:30 PM
=OTS=G-Man =OTS=G-Man is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
should be something like

PHP Code:
<?
$activeadmlist 
"user_list.txt";
$current file_get_contents($activeadmlist);
$pos strpos($current$_SESSION['username']);

if (
$pos === false)
{
    
$current .= $_SESSION['username']."\n";
    
file_put_contents($activeadmlist$current);
}
else
{
    
//TODO:: do someting
}  

?>
used the code flow from your duplicate post

untested, but should work
Reply With Quote
Reply

Bookmarks


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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
text box with scroll bar silvermane CSS 7 01-16-09 04:03 AM
div css theighost CSS 11 09-14-08 03:30 AM
Using data stored in a text file Philmo PHP 3 04-08-08 02:20 PM
PHP write to text file veeco Script Requests 1 03-02-04 02:14 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 05:28 PM


All times are GMT -5. The time now is 07:37 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)