我正在使用带有链接的WhatsApp api
https://github.com/WHAnonymous/Chat-API/wiki/WhatsAPI-Documentation
在本教程中,我使用以下代码来接收消息:
$username = $get_list['userid'];
$password = $get_list['password'];
$nickname = '';
$debug = "false";
$w = new WhatsProt($username, $nickname, $debug);
try {
$w->connect();
$w->loginWithPassword($password);
$w->sendMessage($username , '');
$s = $w->pollMessage();
} catch (Exception $e) {
echo "Sorry ". $e->getMessage();
}
我收到的信息如下:
tx <stream:features>
tx <readreceipts></readreceipts>
tx <groups_v2></groups_v2>
tx <privacy></privacy>
tx <presence></presence>
tx </stream:features>
tx <auth mechanism="WAUTH-2" user="9195666669">����9195666669��/oNz|$%L�A#u)�1449637609</auth>
rx <start from="s.whatsapp.net"></start>
rx <stream:features></stream:features>
rx <challenge>h�.� �z�It���_�*`�P</challenge>
tx <response>����֖G�����C�NJ�qFz�o� #��NCve</response>
rx <success t="1449637762" props="4" kind="free" status="active" creation="1449574308" expiration="1481110308">Ԕ��F��>����(�]I�</success>
tx <presence name=""></presence>
tx <message to="9195666669@s.whatsapp.net" type="text" id="458GQvvffv1so0" t="1449637610" notify="">
tx <body></body>
tx </message>
rx <ib from="s.whatsapp.net">
rx <offline count="0"></offline>
rx </ib>
rx <presence from="9195666669@s.whatsapp.net"></presence>
rx <ack from="9195666669@s.whatsapp.net" class="message" id="458GdQvvfv1so0" t="1449637762"></ack>
rx <presence from="9195666669@s.whatsapp.net" type="unavailable" last="1449637445"></presence>
我没有在代码中编写任何print_r()
,只是它正在打印代码。我不想打印此代码,而是希望将其存储到变量中。如何将其存储到变量中?
答案 0 :(得分:1)
如果您可以控制调用print_r
的代码,那么您可以将输出直接发送到变量:$var_info = print_r($var,true);
- 请参阅https://stackoverflow.com/a/5762520/3012550
但是,由于函数定义is part of the library(第1788行),您似乎无法控制输出。因此,您可以使用此处所述的ob_start:https://stackoverflow.com/a/4798178/3012550
ob_start();
functionThatCallsPrintR();
$output = ob_get_clean();
// $output contains everything outputed between ob_start() and ob_get_clean()