0

I have a website which is running in Joomla 2.5 with MyBlog. I am creating a external application which takes data from MyBlog tables and displays to website users.

In MyBlog comment tables, there is a column name 'comment_author_data'. In this column the data inside looks something like this: {"name":"xxxxx","email":"xxxx@gmail.com","id":"xxx"}

I want to access the value from the name and Email Id and Id from the data.

How do I access them using PHP ?

Any help will be appreciated.

4

1 回答 1

2

That looks like a json string. you can access the values of name and email by using json_decode().

<?php 

$string = ' {"name":"xxxxx","email":"xxxx@gmail.com","id":"xxx"}';

$data = json_decode($string);

print_r($data);

?>

returns

stdClass Object
(
    [name] => xxxxx
    [email] => xxxx@gmail.com
    [id] => xxx
)

which allows you to access it like so:

print $data->name;

于 2013-10-28T10:15:11.130 回答