Array
(
[0] => 32
[1] => Array
(
[uuid] => 92bbf05c-b49e-4950-9d4a-69c226325131
[conversation_uuid] => CON-ee2287cb-ddb7-47e3-9595-0b4d36ac57e3
[status] => failed
[direction] => outbound
)
)
をし、IDとステータスを取得したい、私は次のコードを持っている:
<?php
require __DIR__ . '/../env.php';
//TransferLog Tropo
ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
header('Content-Type: application/json');
$body = file_get_contents('callnexmo.log');
//$body = json_decode($json, true);
//$id=$_GET['id'];
//$body=array($id, $json);
//$req_dump = print_r($body, true);
//$fp = file_put_contents('callnexmo.log', $req_dump);
$conn = new mysqli($servername, $username, $password, $database);
//foreach ($body as $value)
//{
$status=$body[1]['status'];
$to=$body[1]['to'];
$from=$body[1]['from'];
$id=$body[0];
echo " body = $body";
var_dump($body);
echo " status = $status";
var_dump($status);
echo " id = $id";
var_dump($id);
//rest of the code
をしかし、出力は私に
Warning: Illegal string offset 'status' in /opt/lampp/htdocs/buttoncall/skeleton-application/ficheiros/records/teste.php on line 23
Warning: Illegal string offset 'to' in /opt/lampp/htdocs/buttoncall/skeleton-application/ficheiros/records/teste.php on line 24
Warning: Illegal string offset 'from' in /opt/lampp/htdocs/buttoncall/skeleton-application/ficheiros/records/teste.php on line 25
body = Array
(
[0] => 32
[1] => Array
(
[uuid] => 92bbf05c-b49e-4950-9d4a-69c226325131
[conversation_uuid] => CON-ee2287cb-ddb7-47e3-9595-0b4d36ac57e3
[status] => failed
[direction] => outbound
)
)
string(264) "Array
(
[0] => 32
[1] => Array
(
[uuid] => 92bbf05c-b49e-4950-9d4a-69c226325131
[conversation_uuid] => CON-ee2287cb-ddb7-47e3-9595-0b4d36ac57e3
[status] => failed
[direction] => outbound
)
)
"
status = rstring(1) "r"
id = Astring(1) "A"
を取得します私はこの1つに似たロジックを実行していますが、それは機能していますが、今は私の指を誤植に入れているように見えます。 誰かが私を助けますか?
あなたは入力データを誤解しています。あなたは完全に有効な配列ダンプのような "見た目"の文字列を持っています。データを必要に応じて簡単にアクセスできるように、データを別々に保存する必要があります。このファイルがあなたのコントロールから外れているならば、あなたは正規表現か何かでそれをハックする必要があります。 – mickmackusa
あなたはこれを次のように切り詰めるかもしれません:https://regex101.com/r/3CXktP/1 – mickmackusa
私は答えを投稿しますか? – mickmackusa