$url = "http://stackoverflow.com/robots.txt"; $contents = file_get_contents($url); echo strtolower($contents), '<br>'; echo substr_count($contents, 'user-agent'); 

This code is trying to get the number of directives "user-agent", gives me - 0
What not so tell me

    1 answer 1

    You forgot to translate everything in lower case

     $url = "http://stackoverflow.com/robots.txt"; $contents = file_get_contents($url); $contents = strtolower($contents); echo $contents, '<br>'; echo substr_count($contents, 'user-agent'); 
    • Well, or normally write User-Agent - nick
    • $ url = " stackoverflow.com/robots.txt "; $ contents = null; $ contents = file_get_contents ($ url); echo substr_count (strtolower ($ content), 'user-agent'); This gives - 0 - Rimarx