Jump to content

Recommended Posts

I need to extract data from this, i need 
latd , latm and lats.
How to search the array and return the values ?
result i need
$latd = 55 
$latm = 56 
$lats = 41.19

 

$url1 = "https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Broadwood_Stadium&rvsection=0";
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $url1);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0);
$response1 = curl_exec($ch1);
curl_close($ch1);
$response_a1 = json_decode($response1, true);
$dist = $response_a1['query']['pages'];
print_r($dist) ;



 

Array
(
[3750990] => Array
(
[pageid] => 3750990
[ns] => 0
[title] => Broadwood Stadium
[revisions] => Array
(
[0] => Array
(
[contentformat] => text/x-wiki
[contentmodel] => wikitext

  • => {{use dmy dates|date=March 2012}}
    {{refimprove|date=January 2010}}
    {{Infobox venue
    | image = [[File:Broadwood Stadium.jpg|250px]]
    | caption =
    | pushpin_map =
    | pushpin_mapsize = 250
    | pushpin_map_caption = Location in North Lanarkshire
    | pushpin_label_position = left
    | latd = 55|latm = 56|lats = 41.19 |latNS = N
    | longd = 4|longm = 02|longs = 13.51 |longEW = W
    | location = [[Cumbernauld]], [[scotland]]
    | opened = 1994
    | owner = Broadwood Stadium Company (owned by [[North Lanarkshire Council]])[http://news.bbc.co.uk/sport1/hi/football/teams/c/clyde/7977659.stm Council company to sue Clyde FC], [[bBC Sport]], 2 April 2009.
    | surface = [[Artificial turf|3G artificial pitch]][http://www.clydefc.co.uk/news/2012/05/31/4117/ Club Statement: Stadium Update]
    | construction_cost = £8 million
    | architect = Walker Group
    | tenants = [[Clyde F.C.]] (1994 - Present)
    [[Airdrieonians F.C. (1878)|Airdrieonians]] (1994 -1998)
    [[Cumbernauld Colts F.C.|Cumbernauld Colts]] (2012 - Present)
    [[scottish Rugby Academy|Scottish Rugby Academy, West]] (2015 - Present)
    | dimensions = 112 x 76 yards (pitch)
    | seating_capacity = {{SPFL-stadiums|clyde}}
    }}

    '''Broadwood Stadium''', also referred to as simply '''Broadwood''', is a multi-use community [[stadium]] and sports complex situated in [[Cumbernauld]], [[North Lanarkshire]], [[scotland]]. The stadium was opened in 1994 and since then has been the home venue of [[Clyde F.C.]], [[Cumbernauld Colts F.C.]] and the home of [[bT Sport]] [[scottish Rugby Academy]], Glasgow and the West since 2015.

    It has staged the final of Scottish footballs' [[scottish Challenge Cup]] on four occasions and Scottish rugbys' [[Royal Bank of Scotland|RBS]] [[scottish Cup (rugby union)|Finals Day]].http://www.scottishrugby.org/news/14/03/06/rbs-finals-day-moves-venue The stadium has also held international [[Rugby League]]
    )

    )

    )
    )

 

  •  
Link to comment
https://forums.phpfreaks.com/topic/302123-search-json-and-return-data/
Share on other sites

thank you i have tried with google api but it doesent get the correct location , sow the wiki is my last option. 

I changed the code a bit but i get error.

can you suggest any wikitext parser.

Or to save as array the text eg. the to be the separator of arrays and the = to divide key and value

 

with the explode function or something else

$url1 = "https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Broadwood_Stadium&rvsection=0";
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $url1);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0);
$response1 = curl_exec($ch1);
curl_close($ch1);
$response_a1 = json_decode($response1, true);
$dist = $response_a1['query']['pages'];
$dist2 = $response_a1['query']['pages'][$first_key]['revisions'];
reset($dist);
$first_key = key($dist);
echo $first_key;
print_r($dist2);
$t = array_search("latd",$dist);
echo $t;
PHP Notice:  Undefined variable: first_key 

 

 

the echo of the firs key gives the correct number : 3750990.

Edited by vivis933
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.