1

我正在使用带有链接的 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�&lt;/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()在代码中写任何东西,只有它在打印代码。我不想打印此代码,而是想将其存储到变量中。如何将其存储到变量中?

4

1 回答 1

1

如果您可以控制调用的代码print_r,那么您可以将输出直接发送到变量:$var_info = print_r($var,true);- 请参阅https://stackoverflow.com/a/5762520/3012550

但是,您似乎无法控制输出,因为函数定义是库的一部分(第 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()
于 2015-12-09T05:59:10.260 回答