[PHP] Text file manipulation question.

2003-07-14 Thread Lloyd Bayley
Greetings All!

I'm still in the learning stages of PHP and require some help with a small 
problem.

I need to take a text file which looks like this (and no I can't get it 
output in CSV - damn and blast!)

user1   26:48:59   6 logins 4:28:09 hrs/login
user2   19:07:50 33 logins 0:34:46 hrs/login
user3   12:12:04 18 logins 0:40:40 hrs/login
user49:48:58   9 logins 1:05:26 hrs/login
What I want to do (in PHP) is read the list in and search for a username, 
then display the associated statistics for that user.
I'm hoping to get the logistics right first before wrapping it in a form.
Breaking it up into a list works well, except for the fact that the spaces 
between elements are not necessarily the same. (bother!)

Any suggestions, like for example to convert a string of spaces (greater 
than 1) to a comma perhaps to facilitate easier list building?

Cheers,

Lloyd. :-)
PS: I'm an old Coldfusion programmer who has seen the lightso I have 
the logics but can't translate it to PHP...therefore, I'm here!  :-)



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Text file manipulation question.

2003-07-14 Thread Lloyd Bayley
Thankyou! That works a treat!

Lloyd. :-)

At 11:36 PM 14/07/2003 +, you wrote:
Lloyd Bayley <[EMAIL PROTECTED]> wrote:
> Greetings All!
>
> I'm still in the learning stages of PHP and require some help with a small
> problem.
>
> I need to take a text file which looks like this (and no I can't get it
> output in CSV - damn and blast!)
>
> user1   26:48:59   6 logins 4:28:09 hrs/login
> user2   19:07:50 33 logins 0:34:46 hrs/login
> user3   12:12:04 18 logins 0:40:40 hrs/login
> user49:48:58   9 logins 1:05:26 hrs/login
>
>
> What I want to do (in PHP) is read the list in and search for a username,
> then display the associated statistics for that user.
> I'm hoping to get the logistics right first before wrapping it in a form.
> Breaking it up into a list works well, except for the fact that the spaces
> between elements are not necessarily the same. (bother!)
> Any suggestions, like for example to convert a string of spaces (greater
> than 1) to a comma perhaps to facilitate easier list building?
 Assuming you read each line of the file into a variable called $line:
   //replace more than one space to a comma
   $newline = ereg_replace('  +', ',', $line);
 Translates:
   user1   26:48:59   6 logins 4:28:09 hrs/login
 To:
   user1,26:48:59,6 logins,4:28:09 hrs/login
>
> Cheers,
>
> Lloyd. :-)
> PS: I'm an old Coldfusion programmer who has seen the lightso I have
> the logics but can't translate it to PHP...therefore, I'm here!  :-)
 Good to hear that!

HTH,

Curt
--
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Searching a test file...

2003-07-14 Thread Lloyd Bayley
Hi people, back again...

Got some help this today (tnx Curt) from the list but for another chunk of 
the code I'm doing...

Now, I can't seem to get the following code to work...
Have included some sample lines from the datafile (acc.txt)
No matter what I do, it always returns "not here" even if there is a 
matchvery frustrating!

Any ideas?

Lloyd. :-)

 Code Begin -



$name_to_write = "user1";
$names = file("acc.txt");
if (in_array($name_to_write, $names))
{
echo "hello";
}
else
{
echo "not here";
}
?>
 Code Finish 

--- Sample Data Begin ---

user1   26:48:59 6 logins   4:28:09 hrs/login
user2   19:07:50   33 logins   0:34:46 hrs/login
user3   12:12:04   18 logins   0:40:40 hrs/login
--- Sample Data End ---



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] PHP & Variables

2003-12-06 Thread Lloyd Bayley
Greetings All,

Have a small problem that I just can't work out. I know it's an easy one 
but it's got me stumped...

I have some code to pull a question out of a database and display it on the 
screen. I also want to store it in a hidden var for
use with the $_POST on the next page.

Currently, the display bit works fine.
The only problem is the hidden var only has the first word of the question 
in itand I'm setting it from the same var!!!

Eg.

If the question is: What is the problem with this stupid thing?
The hidden var will contain: "What"
What am I missing? Why has the rest of the question packed it's things and 
moved out???

Code Snippet

while ($newarray = mysql_fetch_array($result)) {
$qid = $newarray['qid'];
$question = $newarray['question_text'];
echo "$question";  <--- This works 
perfectly.
echo "";   < This returns first word.

Many Thanks In Advance,

Lloyd. :-)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP & Variables

2003-12-06 Thread Lloyd Bayley
Greg,

Sheesh! I had neglected to do that...I've been working with a few different 
languages and I'm starting to confuse them I think.

Thanks for your non-offensive reply.
It's nice to see that you can overlook the little failures we have now and 
again.

Lloyd. :-)

At 09:58 AM 7/12/2003, you wrote:
Hi Lloyd,

use "quote"s around your values

echo "";

Regards,
Greg
--
phpDocumentor
http://www.phpdoc.org
Lloyd Bayley wrote:
Greetings All,
Have a small problem that I just can't work out. I know it's an easy one 
but it's got me stumped...
I have some code to pull a question out of a database and display it on 
the screen. I also want to store it in a hidden var for
use with the $_POST on the next page.

Currently, the display bit works fine.
The only problem is the hidden var only has the first word of the 
question in itand I'm setting it from the same var!!!
Eg.
If the question is: What is the problem with this stupid thing?
The hidden var will contain: "What"
What am I missing? Why has the rest of the question packed it's things 
and moved out???
Code Snippet

while ($newarray = mysql_fetch_array($result)) {
$qid = $newarray['qid'];
$question = $newarray['question_text'];
echo "$question";  <--- This 
works perfectly.
echo "";
< This returns first word.

Many Thanks In Advance,

Lloyd. :-)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Application-level variables

2004-02-08 Thread Lloyd Bayley
Greetings Everyone,

I am still new to PHP but am progressing nicely. I has helped a lot that I 
have had vast experience with ColdFusion (sorry) but have seen the light 
and am now doing rather nicely in PHP.

My question is as follows...

I have certain functions, variables etc that I would like to be active in 
an application-wide state.
CF has an "application.cfm" file that is read in (if it exists in the 
directory) which is used for this purpose.

Is there a similar creature in PHP? If not, how is it best to define 
application-level stuff?

Many Thanks In Advance,

Lloyd. :-)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php