0

In mysql, I have a db column with BLOB data type.

The blob data looks something like this:

{\"Name\":\"Mike Smith\",\"Number\":\"1\"}

or

[{\"Name\":\"Mike Smith\"},{\"Name\":\"Jon Doe\",\"Spaces\":\"1\"},{\"Name\":\"My Space(s)\"},{\"Name\":\"Rear\"}]

I am trying to detect the content in php and saving the string as a variable as such:

{\"Name\":\"Mike Smith\",\"Number\":\"1\"} 
BECOMES -> Mike Smith(1)

And...

[{\"Name\":\"Mike Smith\"},{\"Name\":\"Jon Doe\",\"Number\":\"1\"},{\"Name\":\"My Space(s)\"},{\"Name\":\"Rear\"}]   
BECOMES --> Mike Smith, Jon Doe(1), My Space(s), Rear

I am not familiar with BLOB data type and wanted to get some help from the community. How would I manipulate the BLOB data to above?

Any suggestions will be much appreciated.

2
  • 1
    That looks like JSON data. Why not just parse it with the various JSON functions? Commented Jun 6, 2017 at 3:58
  • You might be right. I am going to give it a try. Thanks! Commented Jun 6, 2017 at 4:00

1 Answer 1

1
<?php

$data = '[{\"Name\":\"Mike Smith\"},{\"Name\":\"Jon Doe\",\"Number\":\"1\"},
{\"Name\":\"My Space(s)\"},{\"Name\":\"Rear\"}]';

$data =  json_decode(stripslashes($data))  ;

 $string = '';
 for ($i=0; $i <sizeof($data) ; $i++) { 

 $d = $data[$i];

 if(isset($d->Number)){
    $number = '('.$d->Number.')';
 }
 else{
    $number = '';
 }

 $string .= ($d->Name).$number.',  ';

}


echo $string;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.