The following code works with an xml script to check if a given email is in a given contact list and then it prints the results. But for some reasons is giving a SUCCESS all the time, even when the email is not found on that given contaact list. BUT when it is supposed to find the email on a given contact list it DOES print the result.
SO what i want to do is say "IF result is not empty then send an email to X"
$ch = curl_init('http://clientes.cupon0km.com/xml.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$result = @curl_exec($ch);
if($result === false) {
echo "Error performing request";
}
else {
$xml_doc = simplexml_load_string($result);
echo 'status is ', $xml_doc->status, '<br/>';
if ($xml_doc->status == 'SUCCESS') {
print_r($result);
} else {
echo 'Error is ', $xml_doc->errormessage, '<br/>';
}
}
Basically what i dont know what to do is on the second if how to say IF $result contains something (meaning it doesnt return as empty) then send an email to X??
How about if($result!=NULL)? Or if($result!='')? THEN send email.
Test if it's truthy:
if($result){
// Send mail
}
It will be falsey (but not false) if it's the empty string.
if($result === false){
echo "Error performing request";
}else if($result){
// Send mail because result is falsy, but not false
}
if(!empty($result))
{
// here you go
}
Per PHP docs:
The following things are considered to be empty:
- "" (an empty string)
- 0 (0 as an integer)
- 0.0 (0 as a float)
- "0" (0 as a string)
- NULL
- FALSE
- array() (an empty array)
- var $var; (a variable declared, but without a value in a class)
what is in xml file as !empty($result) or '' *false* might not work due to the fact a xml doc will always contain something
you might want to include a error code in the xml file if not found