Jump to content

How To Parse A Variable


refiking

Recommended Posts

$text = 'datetime_system=>2010-10-14 02:07:07{~-SePaRaT0R-~}username_system=>test (16){~-SePaRaT0R-~}ip_system=>79.354.76.127';
preg_match('~.*username_system=>.* \(([0-9]+)\).*~i', $text, $matches);

echo $matches[1];

 

Should do what you are looking for.

well if you have control over what the format of $text is and you need it to be a string, I would suggest you serialize the data (array) into a string for $text and then unserialize $text when you need it, which will restore it to the original array. 

 

If you do not have access to change the format of the $text string, assuming the format is regular (looks like what you have up there, but all the time), you could explode at the delimiter loop through and explode at => for the key => value pairs, basically simulating unserialize().  Though you may run into issues if values happen to be your delimiter or => as well...

 

Otherwise the safest way to do it would probably be to do what premiso suggested.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.