maliary Posted July 25, 2007 Share Posted July 25, 2007 Hi, I have the following string - &=120=-&=127=-&=131=-&=135=-&=170=-&=171=-&=174=-&=175=-&=194=-&=196=-&=206=-&=222=-&=230=-&=236=-&=237=-&=240=-&=249=9 249=9 The important part are the numbers e.g. 120,127 and the dash or value after the = and before the & e.g. 236= (-) & The red part. I would like to separete them to get to display the dash only. how would I do this? Link to comment https://forums.phpfreaks.com/topic/61670-string-formatting/ Share on other sites More sharing options...
Barand Posted July 25, 2007 Share Posted July 25, 2007 try <?php $str = '&=120=-&=127=-&=131=-&=135=-&=170=-&=171=-&=174=-&=175=-&=194=-&=196=-&=206=-&=222=-&=230=-&=236=-&=237=-&=240=-&=249=9'; $ar = explode ('&=', $str); $results = array(); foreach ($ar as $val) { if ($val) { list($k,$v) = explode ('=', $val); $results[$k] = $v; } } echo '<pre>', print_r($results, true), '</pre>'; ?> Link to comment https://forums.phpfreaks.com/topic/61670-string-formatting/#findComment-306978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.