我试图从curl输出中获取公司json。如何做到这一点,我得到字符串形式的输出
$ch = curl_init();
$sourcetCompany = "ibm";
curl_setopt($ch, CURLOPT_URL, "https://www.linkedin.com/ta/federator?query=$sourcetCompany&types=company,group,sitefeature");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, true);
$data = curl_exec($ch);
curl_close($ch);
echo "<pre>";
var_dump($data);
RESPONSE
string(7590) "HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=UTF-8
Vary: Accept-Encoding
Date: Fri, 04 Nov 2016 09:05:52 GMT
X-FS-UUID: 56fb860fddcc8314804113c85d2b0000
X-Frame-Options: sameorigin
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Li-Fabric: prod-lsg1
Strict-Transport-Security: max-age=0
Set-Cookie: leo_auth_token="GST:UP8IDWW6ZePOM9inedlUAhtkH_uGMRap7H9qaet8ZeutVTJpH9l_IA:1478250352:10b33d4d41f866dd15373fc77fedac63d1adeee2"; Version=1; Max-Age=1799; Expires=Fri, 04-Nov-2016 09:35:51 GMT; Path=/
Set-Cookie: sl="delete me"; Version=1; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
Set-Cookie: sl="delete me"; Version=1; Domain=.www.linkedin.com; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
Set-Cookie: s_leo_auth_token="delete me"; Version=1; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
Set-Cookie: bcookie="v=2&4cc7d919-0dda-45d2-8e1d-a21707012721"; domain=.linkedin.com; Path=/; Expires=Sun, 04-Nov-2018 20:43:24 GMT
Set-Cookie: bscookie="v=1&201611040905520e857f5f-e8cf-42a8-813b-7a5b523a748aAQGRyRAC-UQHargNV1tszcZotgo0szFZ"; domain=.www.linkedin.com; Path=/; Secure; Expires=Sun, 04-Nov-2018 20:43:24 GMT; HttpOnly
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache, no-store
Transfer-Encoding: chunked
Connection: keep-alive
X-Li-Pop: prod-tmu1
X-LI-UUID: VvuGD93MgxSAQRPIXSsAAA==
Set-Cookie: lidc="b=SGST00:g=2:u=1:i=1478250352:t=1478336752:s=AQGwe2Cg_DoqG7kaCbZsoRK5O78Wsg8g"; Expires=Sat, 05 Nov 2016 09:05:52 GMT; domain=.linkedin.com; Path=/
{"company":{"resultList":[{"displayName":"IBM","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/AAEAAQAAAAAAAAZrAAAAJDhkMDc3MDgxLTQwMDUtNDM0MS04YzczLTJhNGFlNGFiYzEyOQ.png","subLine":"Information Technology and Services; 10,001+ employees","id":"1009","url":"http://www.linkedin.com/company/1009","headLine":"IBM<\/strong>"},{"displayName":"IBM Global Business Services Talent & Engagement","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/AAEAAQAAAAAAAAc3AAAAJDM5NmZmNjE4LTYxNzMtNDMzNC05NDdjLTcwMjY0ZTE0OWM4NA.png","subLine":"Human Resources; 10,001+ employees","id":"164262","url":"http://www.linkedin.com/company/164262","headLine":"IBM<\/strong> Global Business Services Talent & Engagement"},{"displayName":"IBM Canada","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/p/4/000/132/0a5/38ef89e.png","subLine":"Information Technology and Services; 10,001+ employees","id":"291412","url":"http://www.linkedin.com/company/291412","headLine":"IBM<\/strong> Canada"},{"displayName":"IBM Smarter Workforce","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/p/3/005/0b1/325/05adc32.png","subLine":"Human Resources; 10,001+ employees","id":"4498","url":"http://www.linkedin.com/company/4498","headLine":"IBM<\/strong> Smarter Workforce"},{"displayName":"IBM India Private Limited","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/AAEAAQAAAAAAAAg2AAAAJDUyOWE4MmUzLTMyNmItNDZhMi05YTY4LTRlNmI0NDczZmNhZQ.png","subLine":"Information Technology and Services; 10,001+ employees","id":"332798","url":"http://www.linkedin.com/company/332798","headLine":"IBM<\/strong> India Private Limited"},{"displayName":"IBM Watson Marketing","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/AAEAAQAAAAAAAAd2AAAAJGEwMWZiMzk2LTBhY2MtNDMyYy04MjcyLWNhMmQ1ODUwY2EzOQ.png","subLine":"Computer Software; 10,001+ employees","id":"9632","url":"http://www.linkedin.com/company/9632","headLine":"IBM<\/strong> Watson Marketing"},{"displayName":"IBM Global Business Process Services","subLine":"Information Technology and Services","id":"2181981","url":"http://www.linkedin.com/company/2181981","headLine":"IBM<\/strong> Global Business Process Services"},{"displayName":"IBM (SPSS)","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/p/2/000/01c/05c/29ee786.png","subLine":"Computer Software; 1001-5000 employees","id":"4347","url":"http://www.linkedin.com/company/4347","headLine":"IBM<\/strong> (SPSS)"},{"displayName":"IBM Deutschland","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/AAEAAQAAAAAAAAiNAAAAJGY2NDM4ZWEzLTE3NDItNGVlNC1iMmNiLTRiYzQ1MjBhN2I3ZA.png","subLine":"Information Technology and Services; 10,001+ employees","id":"2207460","url":"http://www.linkedin.com/company/2207460","headLine":"IBM<\/strong> Deutschland"},{"displayName":"IBM de Chile","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/p/2/000/0f4/0a7/3605c52.png","subLine":"Information Technology and Services; 1001-5000 employees","id":"2338629","url":"http://www.linkedin.com/company/2338629","headLine":"IBM<\/strong> de Chile"},{"displayName":"IBM Power Systems","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/AAEAAQAAAAAAAAWbAAAAJDVjZjc3ZmRjLTNjYjAtNDM1MC1iNmY2LTI2NzM0NmJiNTFjNA.png","subLine":"Computer Hardware; 10,001+ employees","id":"2677247","url":"http://www.linkedin.com/company/2677247","headLine":"IBM<\/strong> Power Systems"},{"displayName":"IBM Risk Analytics","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/AAEAAQAAAAAAAARkAAAAJDMyMDJhOThmLTdkMjctNDdlNi1iMDhjLTAwMjdhMzFhZGQzOQ.png","subLine":"Computer Software; 10,001+ employees","id":"5919","url":"http://www.linkedin.com/company/5919","headLine":"IBM<\/strong> Risk Analytics"},{"displayName":"IBM Danmark ApS","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/AAEAAQAAAAAAAAh7AAAAJGUzMjQxYTc5LTAzOTQtNDUzNC1iMmEzLTE4YjMzNDExMTIwMQ.png","subLine":"Information Technology and Services; 1001-5000 employees","id":"2277409","url":"http://www.linkedin.com/company/2277409","headLine":"IBM<\/strong> Danmark ApS"},{"displayName":"IBM iX","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/AAEAAQAAAAAAAAP3AAAAJDRiNGI0NDkzLWMzOTYtNDdlMy1hYWVhLTQ2NmVkOWY1ODkxMg.png","subLine":"Information Technology and Services; 10,001+ employees","id":"5902530","url":"http://www.linkedin.com/company/5902530","headLine":"IBM<\/strong> iX"},{"displayName":"IBM Tivoli Software","subLine":"Computer Software; 10,001+ employees","id":"13888","url":"http://www.linkedin.com/company/13888","headLine":"IBM<\/strong> Tivoli Software"},{"displayName":"IBM Spectrum Computing","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/AAEAAQAAAAAAAAd_AAAAJGRlMDc1ZjE2LTVmZmEtNGQwNC05ZmNhLTNhZDQ3NzMyZTEyOA.png","subLine":"Computer Software; 501-1000 employees","id":"6941","url":"http://www.linkedin.com/company/6941","headLine":"IBM<\/strong> Spectrum Computing"},{"displayName":"IBM Argentina","subLine":"Information Technology and Services","id":"1831400","url":"http://www.linkedin.com/company/1831400","headLine":"IBM<\/strong> Argentina"},{"displayName":"IBM UrbanCode Products","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/p/2/005/05d/1cf/15dbd44.png","subLine":"Computer Software; 51-200 employees","id":"149926","url":"http://www.linkedin.com/company/149926","headLine":"IBM<\/strong> UrbanCode Products"},{"displayName":"IBM DemandTec Solutions","imageUrl":"https://media.licdn.com/mpr/mpr/shrink_100_100/p/1/000/18f/079/3164028.png","subLine":"Computer Software; 10,001+ employees","id":"8830","url":"http://www.linkedin.com/company/8830","headLine":"IBM<\/strong> DemandTec Solutions"},{"displayName":"IBM India Private Limited","subLine":"Computer Software","id":"8985085","url":"http://www.linkedin.com/company/8985085","headLine":"IBM<\/strong> India Private Limited"}]}}"
答案 0 :(得分:2)
您可以从curl
获得结果并执行json_decode($result, true)
,这会将结果作为数组返回。
并设置
curl_setopt($ch, CURLOPT_HEADER, false);
仅获取json
数据回复