I
I
Ismar2015-11-14 15:33:48
PHP
Ismar, 2015-11-14 15:33:48

How to find and cut text?

Please tell me how to extract the text from here. The text is selected ->
The text can be completely different, you need to cut out everything that is in the " " that comes after the "text":
{"ok":true,"result":[{"update_id":125804848, "message":{ "message_id":28,"from":{"id":178282468,"first_name":"Ismar","last_name":"Suleymanov"},
"chat":{"id":178282468,"first_name":" Ismar","last_name":"Suleymanov","type":"private"},"date":1447495291,"text":" asdasd "}},{"update_id":125804849, "message":{"message_id ":29,"from":{"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Valera Karmanov, 2015-11-14
@Ismar

Here's the code for you to see...

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.telegram.org/bot155786728:AAHmcineLW6WFxBs6XuH0liWYuM0W1lqqKQ/getUpdates');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
$code = json_decode(curl_exec($curl));
curl_close($curl);
print_r($code);

// вывод всех записей...
foreach($code->result as $item)
{
  echo $item->message->text.'<br>';
}

// вывод определенной записи по порядковому номеру...
echo $code->result[0]->message->text;

?>

E
entermix, 2015-11-14
@entermix

php.net/manual/en/function.json-decode.php

I
Ilya Beloborodov, 2015-11-15
@kowap

$json='{"ok":true,"result":[{"update_id":125804848, "message":{"message_id":28,"from":{"id":178282468,"first_name":"Ismar","last_name":"Suleymanov"},
"chat":{"id":178282468,"first_name":"Ismar","last_name":"Suleymanov","type":"private"},"date":1447495291,"text":"asdasd"}},{"update_id":125804849, "message":{"message_id":29,"from":{"id":178282468,"first_name":"Ismar","last_name":"Suleymanov"},
}}]}';

var_dump(json_decode($json));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question