arpak arpak - 6 days ago 6
PHP Question

php search for work on specific url

i want to search for a word on example.com/page and if that word exist do nothing, if that word does NOT exist then send me mail via shell_exec

$command1 = exec("mail -s 'title' info@example.com <<< 'message'");
$text1 = file_get_contents('http://example.com/page');
$intext1 = strpos($text1, 'tvshenja1') !== false; // note !==, not !=
echo $intext1 ? 'do nothing' : $command1;


i use this code but in whatever is the result (exist or not exist) it send me mail

if i try with like this

echo $intext1 ? 'do nothing' : 'word dont exist';


then it show me message word dont exist but when i try to use $command1 then in both cases it send message to my mail

Answer

The $command1 variable contains the result of the exec function call (which sends you the email).

If you want to send the mail only if the text was found in the content of the page - you should call the exec function only in such case:

$text1 = file_get_contents('http://example.com/page');
$intext1 = strpos($text1, 'tvshenja1') !== false; // note !==, not !=

if ($intext1) {
    echo 'do nothing';
} else {
    echo exec("mail -s 'title' info@example.com  <<< 'message'");
}