aximbigfan Posted March 15, 2008 Share Posted March 15, 2008 Hi. I'm coding a PHP log viewer, and one thing is that before it only supported 2 logs at a time. Now, I want to make it support an unlimited amount of logs. This thign is, that I need to find a way to store multiple values in one variable, because when a user saves the loginfo to the ini file, it needs to come out liek this: $log1 = "FILE:elog.txt: NAME:Error Log:" how could I do that? And then set those values in an array? Chris Quote Link to comment Share on other sites More sharing options...
Stooney Posted March 15, 2008 Share Posted March 15, 2008 With a delimiter such as '|'. So in the log you would see: FILE:elog.txt|NAME:Error Log| FILE:elog2.txt|NAME:Error Log2| etc... Now to get those into an array (assume all of the log data is in $log) $array=explode("|", $log); That will make something like Array( 0 0 - FILE:elog.txt 1 - NAME:Error Log 1 0 - FILE:elog2.txt 1 - NAME:Error Log2 ) Hope it made sense. Quote Link to comment Share on other sites More sharing options...
aximbigfan Posted March 16, 2008 Author Share Posted March 16, 2008 Thanks! I'll try this.. Chris Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 16, 2008 Share Posted March 16, 2008 Alternatively you can use regex. <?php $subject = 'FILE:elog.txt|NAME:Error Log FILE:elog2.txt|NAME:Error Log2|'; if (preg_match('/FILE:([^|])++|NAME:([^|\\r\\n])++/', $subject, $matches) ) { print_r($matches); } else { // no matches found } ?> Quote Link to comment Share on other sites More sharing options...
aximbigfan Posted March 16, 2008 Author Share Posted March 16, 2008 Ok, I'll keep that in mind as backup, thanks! Chris Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 16, 2008 Share Posted March 16, 2008 It's a better way of doing it IMO. I would use it as a primary. For one, it isolates JUST the information you want Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.