display provider name form hostname

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Rechter

    display provider name form hostname

    Hi,

    I only want to display the provider name from a hostname, so I need to
    divide the string to take only de characters from after the before last dot.

    For example:

    dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"

    adsl-dc-4d454.adsl.wana doo.nl -I only wanna display "wanadoo.nl "


    I tried with "substr()", but than you have to know the exact positions, and
    that's different in a hostname.

    Anybody knows if this possible?

    kind regards,

    Eric


  • Eric Rechter

    #2
    Re: display provider name form hostname

    Hi,
    >
    I only want to display the provider name from a hostname, so I need to
    divide the string to take only de characters from after the before last
    dot.
    >
    For example:
    >
    dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"
    >
    adsl-dc-4d454.adsl.wana doo.nl -I only wanna display "wanadoo.nl "
    >
    >
    I tried with "substr()", but than you have to know the exact positions,
    and that's different in a hostname.
    >
    Anybody knows if this possible?
    >
    kind regards,
    >
    Eric
    >
    i found this solution:

    <?php
    $host = "dsl-083-247-088-130.solcon.nl";

    $char = 2;
    $_count_dot = 0;
    while ($count_dot != 2){
    $char++;
    $dot = substr($host, -$char, 1);
    if ($dot == "."){
    $count_dot++;
    }
    }
    echo substr($host, -$char+1);
    ?>


    Comment

    • Rik

      #3
      Re: display provider name form hostname

      Eric Rechter wrote:
      >Hi,
      >>
      >I only want to display the provider name from a hostname, so I need
      >to divide the string to take only de characters from after the
      >before last dot.
      >>
      >For example:
      >>
      >dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"
      >>
      >adsl-dc-4d454.adsl.wana doo.nl -I only wanna display "wanadoo.nl "
      >>
      >>
      >I tried with "substr()", but than you have to know the exact
      >positions, and that's different in a hostname.
      >>
      >Anybody knows if this possible?
      >>
      >kind regards,
      >>
      >Eric
      >>
      >
      i found this solution:
      >
      <?php
      $host = "dsl-083-247-088-130.solcon.nl";
      >
      $char = 2;
      $_count_dot = 0;
      while ($count_dot != 2){
      $char++;
      $dot = substr($host, -$char, 1);
      if ($dot == "."){
      $count_dot++;
      }
      }
      echo substr($host, -$char+1);

      Maybe this is part of a solution:
      PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


      Else, your code shorter:
      $string = "dsl-083-247-088-130.solcon.nl";
      preg_match('/[^.]+\.[^.]+$/',$string,$matc h);
      $host = $match[0];

      Grtz,
      --
      Rik Wasmus


      Comment

      • Miguel Cruz

        #4
        Re: display provider name form hostname

        "Eric Rechter" <erikrechter@so lcon.nlwrote:
        I only want to display the provider name from a hostname, so I need to
        divide the string to take only de characters from after the before last dot.
        >
        For example:
        >
        dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"
        $hostname = "dsl-083-247-088-130.solcon.nl";
        $parts = explode('.', $hostname);
        if (count($parts) >= 2)
        $provider_name =
        $parts[count($parts) - 2] . '.' . $parts[count($parts) - 1];
        else
        $provider_name = $hostname;

        miguel
        --
        Photos from 40 countries on 5 continents: http://travel.u.nu
        Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
        Airports of the world: http://airport.u.nu

        Comment

        • Rik

          #5
          Re: display provider name form hostname

          Miguel Cruz wrote:
          "Eric Rechter" <erikrechter@so lcon.nlwrote:
          >I only want to display the provider name from a hostname, so I need
          >to divide the string to take only de characters from after the
          >before last dot.
          >>
          >For example:
          >>
          >dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"
          >
          $hostname = "dsl-083-247-088-130.solcon.nl";
          $parts = explode('.', $hostname);
          if (count($parts) >= 2)
          $provider_name =
          $parts[count($parts) - 2] . '.' . $parts[count($parts) - 1];
          else
          $provider_name = $hostname;
          Well, if we're going that way:
          $host = implode('.',arr ay_slice(explod e('.',$hostname ),-2));

          Grtz,
          --
          Rik Wasmus


          Comment

          • Miguel Cruz

            #6
            Re: display provider name form hostname

            "Rik" <luiheidsgoeroe @hotmail.comwro te:
            Miguel Cruz wrote:
            >"Eric Rechter" <erikrechter@so lcon.nlwrote:
            >>I only want to display the provider name from a hostname, so I need
            >>to divide the string to take only de characters from after the
            >>before last dot.
            >>>
            >>For example:
            >>>
            >>dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"
            >>
            >$hostname = "dsl-083-247-088-130.solcon.nl";
            >$parts = explode('.', $hostname);
            >if (count($parts) >= 2)
            > $provider_name =
            > $parts[count($parts) - 2] . '.' . $parts[count($parts) - 1];
            >else
            > $provider_name = $hostname;
            >
            Well, if we're going that way:
            $host = implode('.',arr ay_slice(explod e('.',$hostname ),-2));
            You win this time... but I'll be back!

            miguel
            --
            Photos from 40 countries on 5 continents: http://travel.u.nu
            Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
            Airports of the world: http://airport.u.nu

            Comment

            • Rik

              #7
              Re: display provider name form hostname

              Miguel Cruz wrote:
              "Rik" <luiheidsgoeroe @hotmail.comwro te:
              >Miguel Cruz wrote:
              >>"Eric Rechter" <erikrechter@so lcon.nlwrote:
              >>>I only want to display the provider name from a hostname, so I need
              >>>to divide the string to take only de characters from after the
              >>>before last dot.
              >>>>
              >>>For example:
              >>>>
              >>>dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl"
              >>>
              >>$hostname = "dsl-083-247-088-130.solcon.nl";
              >>$parts = explode('.', $hostname);
              >>if (count($parts) >= 2)
              >> $provider_name =
              >> $parts[count($parts) - 2] . '.' . $parts[count($parts) - 1];
              >>else
              >> $provider_name = $hostname;
              >>
              >Well, if we're going that way:
              >$host = implode('.',arr ay_slice(explod e('.',$hostname ),-2));
              >
              You win this time... but I'll be back!
              Hehehe, oneliners are fun to make up, but often a terrible thing in real
              code :-). It's usually better to be a bit more verbose to keep the code
              legible for future coders. (Even for yourself after a year. I've cursed my
              own cryptic code quite often in the past).

              Grtz,
              --
              Rik Wasmus


              Comment

              Working...