Jump to content

String formatting


maliary

Recommended Posts

 

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

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

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.