我正在使用WHMCS的API,并在curl中獲得回應。我必須準確地從第25行抓取值。回應看起來像這樣。
array(1) {
["product"]=>
array(1) {
[0]=>
array(41) {
["id"]=>
int(107) // this is line 25
我必須抓取括號內的整數(隨后在我的bash腳本中把它作為一個變數)。對于上面的例子,它是107.
。是否有一個更簡單的方法來實作這個目標。
======
這是我的php檔案包含。
<?php
/**。
* WHMCS的API呼叫樣本
*
* @package WHMCS
* @author WHMCS Limited < development@whmcs.com>
* @copyright Copyright (c) WHMCS Limited 2005-2016
* @license http://www.whmcs.com/license/ WHMCS Eula
* @version $Id$
* @link http://www.whmcs.com/
*/
//API連接詳情
$whmcsUrl = "https://my.whmcswebsite.net/"/span>。
//對于WHMCS 7.2及以后的版本,我們建議使用API認證憑證對。
//了解更多資訊:http://docs.whmcs.com/API_Authentication_Credentials 。
///在WHMCS 7.2之前,可以使用一個管理員用戶名和管理員密碼的md5哈希。
$username = "something"/span>;
$password = "something";
//設定職位值
$postfields = array(
'username' => $username,
'password' => $password,
'action' => 'GetClientsProducts',
'domain' => 'fifi790.mydomain.net',
'responsetype' => 'json',
);
//呼叫API
$ch = curl_init()。
curl_setopt($ch, CURLOPT_URL, $whmcsUrl . 'includes/api.php')。)
curl_setopt($ch, CURLOPT_POST, 1) 。
curl_setopt($ch, CURLOPT_TIMEOUT, 30) 。
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1) 。
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1) 。
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2) 。
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields) )。)
$response = curl_exec($ch)。
if (curl_error($ch) {
die('Unable to connect: ' . curl_errno($ch) . ' - ' . curl_error($ch) )。
}
curl_close($ch)。
//解碼回應
$jsonData = json_decode($response, true);
//轉儲陣列結構以供檢查。
var_dump($jsonData)。
uj5u.com熱心網友回復:
你可以用sed來做這件事
從檔案中讀取第25行line=$(sed '25! d' file)
移除括號前后的所有內容
echo ${line} | sed 's/. *(//g' | sed 's/).*/g'
uj5u.com熱心網友回復:
如果你只需要在一個變數中的第25行的數字,你可以使用這個sed
var=$(sed -n '25s/.*(([0-9]*))/1/p'/span> $file)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/319770.html
標籤:
上一篇:vue的全域事件總線
