Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6183051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:18:08+00:00 2026-05-24T01:18:08+00:00

I have this code: <?php $url = http://asdsfsfsfsfsdfad.com; $file = file_get_contents($url); if(preg_match(/<title>(.+)<\/title>/i,$file,$m)) print $m[1];

  • 0

I have this code:

<?php
$url = "http://asdsfsfsfsfsdfad.com";
$file = file_get_contents($url);

if(preg_match("/<title>(.+)<\/title>/i",$file,$m))
    print "$m[1]";
else
    print "The page doesn't have a title tag";
?>

It works fine when the url is a proper url, but when I put in nonsense then I get two warning messages:

Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Navn eller tjeneste ukendt in /var/www/web17/web/administration/custom_pages.php(71) : eval()'d code on line 4
Warning: file_get_contents(http://asdsfsfsfsfsdfad.com) [function.file-get-contents]: failed to open stream: php_network_getaddresses: getaddrinfo failed: Navn eller tjeneste ukendt in /var/www/web17/web/administration/custom_pages.php(71) : eval()'d code on line 4

Any way to prevent this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:18:09+00:00Added an answer on May 24, 2026 at 1:18 am

    The easiest solution would be to just suppress the error:

    echo @file_get_contents("http://asdsfsfsfsfsdfad.com");
    

    However, error suppression is generally considered bad practise because you never know what went wrong, so it is better to have a handler that selectively handles errors, for instance

    set_error_handler(function($code, $message) {
        return ($code === E_WARNING && strpos($message, 'php_network_getaddresses'));
    });
    echo file_get_contents("http://asdsfsfsfsfsdfad.com");
    

    This would suppress any E_WARNINGS with a message containing ‘php_network_getaddresses’. Any other Warnings will not be suppressed.

    In addition, you dont want Regex to parse HTML, but use an HTML Parser, like one of those given in

    • How do you parse and process HTML/XML in PHP?

    So you could do it with DOM. Again, either using Error Suppression (bad)

    $dom = new DOMDocument;
    @$dom->loadHTMLFile("http://asdsfsfsfsfsdfad.com");
    $titles = $dom->getElementsByTagName('title');
    echo $titles->length ? $dom->nodeValue : 'No Title found';
    

    Or selectively suppressing network errors:

    set_error_handler(function($code, $message) {
        return ($code === E_WARNING && strpos($message, 'php_network_getaddresses'));
    });
    
    $dom = new DOMDocument;
    $dom->loadHTMLFile("http://asdsfsfsfsfsdfad.com");
    $titles = $dom->getElementsByTagName('title');
    echo $titles->length ? $titles->item(0)->nodeValue  : 'No Title found';
    

    However, this will then result in parsing errors because loadHTMLFile will not return any HTML, so to suppress the parsing errors as well, you’d have to do:

    set_error_handler(function($code, $message) {
        return ($code === E_WARNING && strpos($message, 'php_network_getaddresses'));
    });
    libxml_use_internal_errors(true);
    $dom = new DOMDocument;
    $dom->loadHTMLFile("http://asdsfsfsfsfsdfad.com");
    libxml_clear_errors();
    $titles = $dom->getElementsByTagName('title');
    echo $titles->length ? $titles->item(0)->nodeValue : 'No Title found';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this jquery code: $.ajax({ type: GET, url: http://api.ipinfodb.com/v2/ip_query.php?key=3b80b5588c22d2a03c0e6979d1e85e397e043646c4a65ffe47ff01d47bce51e, dataType: xml, success: function(xml)
Example current URL http://www.domain.com/subdomain/install/finish.php I use this code to get the current URL. $url
I have this code: var ajaxLoader = $('.ajaxLoader', lpWindow); $.ajaxSetup({ url: 'http://www.server.foo/setMessage.php', type: 'POST',
i tried this code to hide the php file extension i have this url
I have this code <?php function get(){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, http://stackoverflow.com/); curl_setopt($ch,
I have this page where I am doing testing http://www.comehike.com/test_fb_connect.php The button works fine
I have this code <?php session_start(); if (isset($_GET[cmd])) $cmd = $_GET[cmd]; else die(You should
Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
Hi there I have this code NSLog(@%@,URLRequestQueryString); NSString *sendToServerString = [NSString stringWithFormat:@http://mydomain.co.uk/req.php%@,URLRequestQueryString]; NSURL *sendToServer
I have a test.php page in this page , there is a url .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.