$url = 'http://example.com/article'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, true); curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($httpCode == 200){ echo "Article exists"; } else { echo "Article does not exist"; }
$url = 'http://example.com/article'; $content = @file_get_contents($url); if($content !== false){ echo "Article exists"; } else { echo "Article does not exist"; }In this example, we use the file_get_contents function to retrieve the content of the article URL. If the function returns false, we can assume that the article does not exist. Overall, there are many PHP packages and libraries available for checking the existence of content, such as the cURL library and file_get_contents function. These tools can help simplify web development and enhance the functionality of PHP applications.