How PHP extracts data from JSON,

Source: Internet
Author: User
Tags parse error
I am now studying the API of Baidu Map, encountered some problems
For example, I have extracted such information, information in the http://likeapp.duapp.com/yx/4.php, but there is a lot of content, Baidu's interpretation of the field is such http://developer.baidu.com/map/ Direction-api.htm#place8_3
How do I extract data from stepinstruction This field ah, ask the master to answer


Reply to discussion (solution)

Json_decode

Json_decode? Encode a string in JSON format

Very simple

Json_decode? Encode a string in JSON format

Very simple

Master can for me this instance to a code ah, after giving, I must be carefully read the tutorial.

Set the name of the array you printed out as $ar, then

Array_walk_recursive ($ar, function ($v, $k) {if ($k = = ' stepinstruction ') echo $v;});

Have
Ride 12-Way(or 16-way, 8-way, 2-way Walk 360 m, arrive at the finish station ride 19-Way(or 28-way walk 270 m, arrive at the finish station ride 17-Way, after 3 stops, reached the Shanshui people station walk 820 meters, reached the terminal

$ar = Json_decode ($json, true);
Array_walk_recursive ($ar function ($v, $k) {if ($k = = ' stepinstruction ') echo $v;});
Like this?

$ar = Json_decode ($json, true);
Array_walk_recursive ($ar function ($v, $k) {if ($k = = ' stepinstruction ') echo $v;});
Like this?

Error Parse Error:syntax error, unexpected t_function in E:\PHPnow-1.5.6\htdocs\4.php on line 12

Array_walk_recursive ($ar , function ($v, $k) {if ($k = = ' stepinstruction ') echo $v;});
There's a comma missing!

If your PHP version is less than 5.3

Array_walk_recursive ($ar, ' FUNV '), function func ($v, $k) {  if ($k = = ' stepinstruction ') echo $v;}

Array_walk_recursive ($ar , function ($v, $k) {if ($k = = ' stepinstruction ') echo $v;});
There's a comma missing!

If your PHP version is less than 5.3

Array_walk_recursive ($ar, ' FUNV '), function func ($v, $k) {  if ($k = = ' stepinstruction ') echo $v;}

Warning:array_walk_recursive () [function.array-walk-recursive]: Unable to call FUNV ()-function does not exist in E:\PHP Now-1.5.6\htdocs\4.php on line 12


Array_walk_recursive ($ar , function ($v, $k) {if ($k = = ' stepinstruction ') echo $v;});
There's a comma missing!

If your PHP version is less than 5.3

Array_walk_recursive ($ar, ' FUNV '), function func ($v, $k) {  if ($k = = ' stepinstruction ') echo $v;}

Warning:array_walk_recursive () [function.array-walk-recursive]: Unable to call FUNV ()-function does not exist in E:\PHP Now-1.5.6\htdocs\4.php on line 12



FUNV->func must be upstairs with the hands slipped,

Array_walk_recursive ($ar, ' func '), function func ($v, $k) {  if ($k = = ' stepinstruction ') echo $v;}



Array_walk_recursive ($ar , function ($v, $k) {if ($k = = ' stepinstruction ') echo $v;});
There's a comma missing!

If your PHP version is less than 5.3

Array_walk_recursive ($ar, ' FUNV '), function func ($v, $k) {  if ($k = = ' stepinstruction ') echo $v;}

Warning:array_walk_recursive () [function.array-walk-recursive]: Unable to call FUNV ()-function does not exist in E:\PHP Now-1.5.6\htdocs\4.php on line 12



FUNV->func must be upstairs with the hands slipped,



Yes, I want to do it one by one, the data above is "take 12 road (or 16 Road, 8 Road, 2 Road), after 4 station, arrive at the East Haven Trade City station walk 360 meters, arrive at the finish station take 19 road (or 28 road), after 5 station, arrive at the Sea Lotus Edge Station walk 270 meters, arrive at the finish station , reach the Shanshui family station on foot 820 meters, arrive at the finish station "
Into this:
Plan one: Take 12 road (or 16 Road, 8 Road, 2 Road), pass 4 station, arrive at East Haven Trade City station walk 360 meters, arrive terminal
Plan two: Take 19 road (or 28 road), after 5 station, reached the Sea Lotus Edge Station walk 270 meters, reached the terminal
Plan three: Take 17 road, after 3 stations, reached the Shanshui people station walk 820 meters, reached the terminal

I want to do this, just add a br.

function func ($v, $k) {  static $cnt =1;  if ($k = = ' Stepinstruction ')   {       echo ' scheme ', $cnt, ': ', $v, '
'; }}

34567 function func ($v, $k) {  static $cnt =1;  if ($k = = ' Stepinstruction ')   {       echo ' scheme ', $cnt, ': ', $v, '
'; $cnt + +;

CSDN is disgusting, two floors above, the first to forget $cnt + +. LZ problem solved on the knot, say this basic problem, or read more reading.

CSDN is disgusting, two floors above, the first to forget $cnt + +. LZ problem solved on the knot, say this basic problem, or read more reading.

There is also a problem, is to get the data can not do not page code AH ride 12-Way(or 16-way, 8-way, 2-way

Remove the code and get the plain text information.

Array_walk_recursive ($ar, ' func '), function func ($v, $k) {  if ($k = = ' stepinstruction ') echo $v;}

Find a regular expression

It is not the right thing to do, why do you have to be reluctant to do?

It is not the right thing to do, why do you have to be reluctant to do?

No, I mean to get the data after the $v, because there is a Web page code exists, I want the code to get rid of the text message

Oh
echo Strip_tags ($v);

Oh
echo Strip_tags ($v);

This is a great function, 3Q.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.