Check cURL output PHP

curl, php

Solution

You may be getting extra white spaces before or after the OK or other characters.

I suggest doing what the people above suggested by testing what is exactly inside the array with `var_dump($curlresult);` or `print_r($curlresult);`

But alternatively you could instead of matching that $curlresult equals only "OK", you could test if $curlresult contains "OK" inside of it.

<?php

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://blablabla.com");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $curlresult=curl_exec ($ch);
      curl_close ($ch);



    if (preg_match("/OK/i", $curlresult)) {
        $result = "The curl action was succeeded! (OUTPUT of curl is: ".$curlresult.")";
    } else {
        $result = "The curl action has FAILED! (OUTPUT of curl is: ".$curlresult.")";
    }

echo $result;

?>

Problem

i'm trying to check the output of a cURL. ``` <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://blablabla.com"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $curlresult=curl_exec ($ch); curl_close ($ch); if ($curlresult == "OK") { $result = "The curl action was succeeded! (OUTPUT of curl is: ".$curlresult.")"; } else { $result = "The curl action has FAILED! (OUTPUT of curl is: ".$curlresult.")"; } echo $result; ?> ``` The URL (https://blablabla.com) is a URL that just displays OK. So, using the code, I would expect to see "The curl action was succeeded! (OUTPUT of curl is: OK)" But, what I do get is: The curl action has FAILED! (OUTPUT of curl is: OK ) I guess i'm making some stupid mistake. How can I check if https://blablabla.com contains "OK"? Thanks!

Original source