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 Link to comment https://forums.phpfreaks.com/topic/96291-get-multiple-values-out-of-variable/ 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. Link to comment https://forums.phpfreaks.com/topic/96291-get-multiple-values-out-of-variable/#findComment-493028 Share on other sites More sharing options...
aximbigfan Posted March 16, 2008 Author Share Posted March 16, 2008 Thanks! I'll try this.. Chris Link to comment https://forums.phpfreaks.com/topic/96291-get-multiple-values-out-of-variable/#findComment-493124 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 } ?> Link to comment https://forums.phpfreaks.com/topic/96291-get-multiple-values-out-of-variable/#findComment-493138 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 Link to comment https://forums.phpfreaks.com/topic/96291-get-multiple-values-out-of-variable/#findComment-493140 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 Link to comment https://forums.phpfreaks.com/topic/96291-get-multiple-values-out-of-variable/#findComment-493143 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.