-1

I'm tasked to change the framework from CakePHP to Codeigniter. In the database there is this JSON like text in one column in order to define the values of 4 select inputs. The text looks like -

a:4:{i:58;s:1:"1";i:59;s:1:"0";i:60;s:1:"0";i:61;s:1:"0";}

Basically it says a(array size which is 4), i(being the id) and in s(i dont know about the first integer but all of its values is just 1 the second integer with the "" means it is the 0=>'None', 1=>'Yes', 2=>'NaN').

This is the previous programmer's code in CakePHP

<?php 
$options_services = array(0=>'None', 1=>'Yes', 2=>'NaN');
?>
<div class="box-body">                    
    <div class="form-group ">        
        <div class="row">    
            <div class="col-md-6">
                <label> Select Service Category</label>   
                <div> 
                    <?php echo $this->Form->input('catservice_id', array('options'=>$catservices,'div' => false, 'label' => false, 'class' => 'form-control','type'=>'select','empty'=>'Please Select Category')); ?>
                </div>
            </div>
            <div class="col-md-6">
                <label> Title <span class="required">*</span></label>   
                <div> 
                    <?php echo $this->Form->input('title', array('div' => false, 'label' => false, 'class' => 'form-control')); ?>
                </div>
            </div> 
        </div>
    </div>
    <div class="form-group ">        
        <div class="row">   
          <?php if(!empty($service_list)): ?>
           <?php foreach($service_list as $key=>$values): ?>
           <div class="col-md-3">
                <label><?php echo $values;?> </label>   
               <div> 
                    <?php echo $this->Form->input('cleaning.'.$key, array('options'=>$options_services,'div' => false, 'label' => false, 'class' => 'form-control','type'=>'select')); ?>
                </div>
            </div> 
            <?php endforeach; ?>
            <?php endif; ?>
        </div>
    </div>    
</div><!-- /.box-body -->
<div class="box-footer">

    <?php
    echo $this->Html->link('Back', array('controller' => 'services', 'action' => 'index'), array('escape' => false, 'class' => 'btn btn-info'));
    ?>
    <button type="submit" class="btn btn-primary">Submit</button>
</div>

i certainly means id

enter image description here

i want to use the JSON like text to be able to use this

enter image description here

I tried json_decode in Codeigniter but it doesnt work. You guys have any idea how I can decode this? Would help me a lot. Thank you!

Azis
  • 192
  • 4
  • 16
  • 2
    https://www.php.net/manual/en/function.unserialize.php and make sure you read that big red warning box. – Sammitch Oct 29 '19 at 00:16
  • There does seem to be a pattern other than what you mentioned. `a:4:{i:58;s:1:"1";i:59;s:1:"0";i:60;s:1:"0";i:61;s:1:"0";}`. `i` likely means *integer*. `s` likely means *string*. The number that immediately follows `s` is likely the string's *length*. – GetSet Oct 29 '19 at 00:16
  • @GetSet im sure i means id coz i located it in the other database table – Azis Oct 29 '19 at 00:17
  • It might be used as an id sure. With Sammitch's reveal that its serialized data though, it certainly stands for integer or something along those lines. – GetSet Oct 29 '19 at 00:19
  • @GetSet im very sure it's id of the values of the select inputs. i located it already. i just dont know how to use this to be able to transform it. i will update my post and give photos – Azis Oct 29 '19 at 00:20
  • @Azis, I don't know if you see Sammitch's comment (the 1st one). Take a look at what is said there. – GetSet Oct 29 '19 at 00:25
  • @Sammitch i got it! THANKS! – Azis Oct 29 '19 at 00:29
  • @GetSet i got it thank you!!! – Azis Oct 29 '19 at 00:30
  • 1
    Glad it worked out – GetSet Oct 29 '19 at 00:32

1 Answers1

0

I got it thanks to @GetSet help.

Using unserialize

See this question : How to use php serialize() and unserialize()

Azis
  • 192
  • 4
  • 16