1

I am using the WhatsApp api with the link

https://github.com/WHAnonymous/Chat-API/wiki/WhatsAPI-Documentation

From this tutorial, I am using the following code to receive the messages:

    $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();
    }

I am getting the messages as follow :

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>

I have not written any print_r() in the code then only it is printing the code. I don't want to print this code, and instead want to store it into a variable. How can I store it into a variable?

Will
  • 24,082
  • 14
  • 97
  • 108
Rohitashv Singhal
  • 4,517
  • 13
  • 57
  • 105
  • you are calling WhatsProt() class's function so it may be taht in these functions containing print_r() anywhere. You must to debug your code... – Krishna Gupta Dec 09 '15 at 05:22
  • Hiii found the code with `print_r()` is only ` public function debugPrint($debugMsg) { if ($this->debug) { if (is_array($debugMsg) || is_object($debugMsg)) { print_r($debugMsg); } else { echo $debugMsg; } return true; } return false; }` – Rohitashv Singhal Dec 09 '15 at 05:34
  • Here's the source for the debugPrint function: https://github.com/WHAnonymous/Chat-API/blob/494f7ccd43b16568cdb2ead8bcd92f705e3cd835/src/whatsprot.class.php – alexanderbird Dec 09 '15 at 05:51

1 Answers1

1

If you had control over the code that calls print_r, then you could send the output directly to a variable: $var_info = print_r($var,true); - See https://stackoverflow.com/a/5762520/3012550

However, it seems you don't have control over the output, since the function definition is part of the library (line 1788). So, you can use ob_start as described here: https://stackoverflow.com/a/4798178/3012550

ob_start();
functionThatCallsPrintR();
$output = ob_get_clean();
// $output contains everything outputed between ob_start() and ob_get_clean()
Community
  • 1
  • 1
alexanderbird
  • 3,847
  • 1
  • 26
  • 35