trim

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

    trim

    this may seem so lame to some, but I have exausted my brain trying to figure
    this out, and therefore throw myself at the group:

    basic breakdown of problem

    $CurrentSite = $_SERVER["HTTP_HOST"];
    <?php echo $CurrentSite ;?>

    I only want the 'domain.com' part to display.. even if the host is
    www.domain.com or whatever.domain .com

    I just want to display the domain.com, am I right in thinking that regular
    expressions would be the solution?

    any assistance would save my sanity.

    Thanks


  • Daniel Tryba

    #2
    Re: trim

    Joe90 <boy_bandreject REMOVE@hotmail. com> wrote:[color=blue]
    > I only want the 'domain.com' part to display.. even if the host is
    > www.domain.com or whatever.domain .com
    >
    > I just want to display the domain.com, am I right in thinking that regular
    > expressions would be the solution?[/color]

    It's a solution, and propable the simpelest if you know how to compose
    one (which is quite trivial so it's best to let you do your own research
    to get the last 2 words seperated by a '.' :).

    An other solution is to count the '.' and if there are more then 2
    to take the substring from the second last '.' (strrpos/substr).

    Comment

    • Ken Robinson

      #3
      Re: trim


      Joe90 wrote:[color=blue]
      > this may seem so lame to some, but I have exausted my brain trying to[/color]
      figure[color=blue]
      > this out, and therefore throw myself at the group:
      >
      > basic breakdown of problem
      >
      > $CurrentSite = $_SERVER["HTTP_HOST"];
      > <?php echo $CurrentSite ;?>
      >
      > I only want the 'domain.com' part to display.. even if the host is
      > www.domain.com or whatever.domain .com
      >
      > I just want to display the domain.com, am I right in thinking that[/color]
      regular[color=blue]
      > expressions would be the solution?[/color]

      One way:
      <?
      $CurrentSite = explode('.',$_S ERVER["HTTP_HOST"]);
      $i = count($CurrentS ite) - 2;
      echo $CurrentSite[$i] . '.' . $CurrentSite[$i+1];
      ?>

      Ken

      Comment

      • Mike Willbanks

        #4
        Re: trim

        > $CurrentSite = $_SERVER["HTTP_HOST"];[color=blue]
        > <?php echo $CurrentSite ;?>
        >
        > I only want the 'domain.com' part to display.. even if the host is
        > www.domain.com or whatever.domain .com[/color]

        Yes a regular expression would be the key.

        You would most likely put your domain at the end and actually have it
        filter everything else. The problem however you will run into when
        building your regular expression is when there is domain.co.uk and the
        similar.

        Mike

        Comment

        • Joe90

          #5
          Re: trim

          ^[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$

          should work ok even with .co.uk :-)

          however how would I extract just the domain part, in the case of
          thisisasub.doma in.com , www.domain.com or what if it was just domain.com the
          script would have to be adaptable to all these scenarios.



          "Mike Willbanks" <pencap@gmail.c om> wrote in message
          news:IUtee.3316 2$Ow2.26135@fe0 6.lga...[color=blue][color=green]
          >> $CurrentSite = $_SERVER["HTTP_HOST"];
          >> <?php echo $CurrentSite ;?>
          >>
          >> I only want the 'domain.com' part to display.. even if the host is
          >> www.domain.com or whatever.domain .com[/color]
          >
          > Yes a regular expression would be the key.
          >
          > You would most likely put your domain at the end and actually have it
          > filter everything else. The problem however you will run into when
          > building your regular expression is when there is domain.co.uk and the
          > similar.
          >
          > Mike[/color]


          Comment

          • Chuck Anderson

            #6
            Re: trim

            Joe90 wrote:
            [color=blue]
            >^[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$
            >
            >should work ok even with .co.uk :-)
            >
            >however how would I extract just the domain part, in the case of
            >thisisasub.dom ain.com , www.domain.com or what if it was just domain.com the
            >script would have to be adaptable to all these scenarios.
            >
            >
            >
            >"Mike Willbanks" <pencap@gmail.c om> wrote in message
            >news:IUtee.331 62$Ow2.26135@fe 06.lga...
            >
            >[color=green][color=darkred]
            >>>$CurrentSi te = $_SERVER["HTTP_HOST"];
            >>><?php echo $CurrentSite ;?>
            >>>
            >>>I only want the 'domain.com' part to display.. even if the host is
            >>>www.domain.com or whatever.domain .com
            >>>
            >>>[/color]
            >>Yes a regular expression would be the key.
            >>
            >>You would most likely put your domain at the end and actually have it
            >>filter everything else. The problem however you will run into when
            >>building your regular expression is when there is domain.co.uk and the
            >>similar.
            >>
            >>Mike
            >>
            >>[/color]
            >
            >
            >
            >[/color]
            Okay I'll go out on a limb? Why not just use - $domain =
            str_replace('ww w.', '', $domain);

            --
            *************** **************
            Chuck Anderson • Boulder, CO

            Integrity is obvious.
            The lack of it is common.
            *************** **************

            Comment

            • Don Freeman

              #7
              Re: trim


              "Chuck Anderson" <websiteaddress @seemy.sig> wrote in message
              news:IYSdnRDhtL xVD-ffRVn-uQ@comcast.com. ..[color=blue]
              > Joe90 wrote:
              >[color=green]
              >>^[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$
              >>
              >>should work ok even with .co.uk :-)
              >>
              >>however how would I extract just the domain part, in the case of
              >>thisisasub.do main.com , www.domain.com or what if it was just domain.com
              >>the script would have to be adaptable to all these scenarios.
              >>[/color]
              > Okay I'll go out on a limb? Why not just use - $domain =
              > str_replace('ww w.', '', $domain);
              >[/color]
              WWW isn't the only domain prefix used, for instance a lot of ISPs have a
              members.domain. com alias as well that points to their subscribers personal
              web sites. Then there is ftp.domain.com, etc..


              Comment

              • Joe90

                #8
                Re: trim

                That is my concern also DON. I will clarify further :

                I wish to only have 'domain.com' in a variable.

                that would mean that all subdomains like:

                whatever.domain .com
                ftp.domain.com
                mail.domain.com

                supercalifragil isticexpialidoc ious.domain.com
                domain.com

                would all except the last one be stripped of the hostname and my variable
                would contain only

                DOMAIN.COM

                It is proving to be a challenge ;-)

                "Don Freeman" <freemand@sonic .net> wrote in message
                news:hAwee.687$ T3.5052@typhoon .sonic.net...
                [color=blue][color=green]
                >>[/color]
                > WWW isn't the only domain prefix used, for instance a lot of ISPs have a
                > members.domain. com alias as well that points to their subscribers personal
                > web sites. Then there is ftp.domain.com, etc..
                >[/color]


                Comment

                • Jason F.

                  #9
                  Re: trim

                  Joe90 wrote:[color=blue]
                  > ^[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$
                  >
                  > should work ok even with .co.uk :-)
                  >
                  > however how would I extract just the domain part, in the case of
                  > thisisasub.doma in.com , www.domain.com or what if it was just domain.com the
                  > script would have to be adaptable to all these scenarios.[/color]

                  If you can't be 100% sure what the intended "base domain" is, then do
                  what many scripts do and simply make it a configuration option.

                  e.g. You can use wildcard DNS for domains such as
                  http://anything.goes.here.dev.basedomain.com, and there's no easy way to
                  know that "anything.goes. here" is the intended host part and
                  "dev.basedomain .com" is the base part just by looking at HTTP_HOST or
                  SERVER_NAME.

                  Comment

                  • Joe90

                    #10
                    Re: trim

                    there has to be another way.. I am sure you can do it with Expression, but I
                    just cant master it. The whole script relies on just being able to pull
                    just the hostname.


                    "Jason F." <jason.newsonly @gmail.com> wrote in message
                    news:J_wee.1631 7$n93.12335@twi ster.nyc.rr.com ...[color=blue]
                    > Joe90 wrote:[color=green]
                    >> ^[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$
                    >>
                    >> should work ok even with .co.uk :-)
                    >>
                    >> however how would I extract just the domain part, in the case of
                    >> thisisasub.doma in.com , www.domain.com or what if it was just domain.com
                    >> the script would have to be adaptable to all these scenarios.[/color]
                    >
                    > If you can't be 100% sure what the intended "base domain" is, then do what
                    > many scripts do and simply make it a configuration option.
                    >
                    > e.g. You can use wildcard DNS for domains such as
                    > http://anything.goes.here.dev.basedomain.com, and there's no easy way to
                    > know that "anything.goes. here" is the intended host part and
                    > "dev.basedomain .com" is the base part just by looking at HTTP_HOST or
                    > SERVER_NAME.[/color]


                    Comment

                    • Don Freeman

                      #11
                      Re: trim


                      "Joe90" <boy_bandreject REMOVE@hotmail. com> wrote in message
                      news:d5e5mh$2ic $1@nwrdmz03.dmz .ncs.ea.ibs-infra.bt.com...[color=blue]
                      >I wish to only have 'domain.com' in a variable.
                      > that would mean that all subdomains like:
                      > whatever.domain .com
                      > ftp.domain.com
                      > mail.domain.com
                      > www.domain.com
                      > supercalifragil isticexpialidoc ious.domain.com
                      > domain.com
                      >
                      > would all except the last one be stripped of the hostname and my variable
                      > would contain only
                      >
                      > DOMAIN.COM[/color]

                      The best I could come up with is to break down your full name (like
                      my.ftp.do.main. com, in the case "do.main.co m" will be the actual domain)
                      into separate elements using the "." as a delimiter. (see
                      http://us2.php.net/manual/en/function.explode.php on how to do this)

                      Then taking the last two elements - domain & com (no sense testing on just
                      the last as there are no domains named thusly) stringing them together with
                      the "." separating them. Then test it using the checkdnsrr function
                      (http://us4.php.net/checkdnsrr) if it passes (won't in this case) then that
                      is your actual domain, if not add the next (going right to left) element to
                      the string with another "." as separator (now you would have do.main.com).
                      Do another checkdnsrr, and so on (though in this case it would pass the
                      test). This would be placed in a loop limited by the number of elements
                      created.
                      -Don Freeman


                      Comment

                      • Jason F.

                        #12
                        Re: trim

                        Don Freeman wrote:[color=blue]
                        > "Joe90" <boy_bandreject REMOVE@hotmail. com> wrote in message
                        > news:d5e5mh$2ic $1@nwrdmz03.dmz .ncs.ea.ibs-infra.bt.com...
                        >[color=green]
                        >>I wish to only have 'domain.com' in a variable.
                        >>that would mean that all subdomains like:
                        >>whatever.doma in.com
                        >>ftp.domain.co m
                        >>mail.domain.c om
                        >>www.domain.com
                        >>supercalifrag ilisticexpialid ocious.domain.c om
                        >>domain.com
                        >>
                        >>would all except the last one be stripped of the hostname and my variable
                        >>would contain only
                        >>
                        >>DOMAIN.COM[/color]
                        >
                        >
                        > The best I could come up with is to break down your full name (like
                        > my.ftp.do.main. com, in the case "do.main.co m" will be the actual domain)
                        > into separate elements using the "." as a delimiter. (see
                        > http://us2.php.net/manual/en/function.explode.php on how to do this)
                        >
                        > Then taking the last two elements - domain & com (no sense testing on just
                        > the last as there are no domains named thusly) stringing them together with
                        > the "." separating them. Then test it using the checkdnsrr function
                        > (http://us4.php.net/checkdnsrr) if it passes (won't in this case) then that
                        > is your actual domain, if not add the next (going right to left) element to
                        > the string with another "." as separator (now you would have do.main.com).
                        > Do another checkdnsrr, and so on (though in this case it would pass the
                        > test). This would be placed in a loop limited by the number of elements
                        > created.
                        > -Don Freeman
                        >[/color]

                        Good solution, except checkdnsrr() isn't implemented for Windows' PHP,
                        and it won't work for domains without a MX, or for valid subdomain
                        websites that do take their mail at the base domain. (eg.
                        www.johnsmith.domain.com could be a valid vhost who gets mail
                        @domain.com rather than @johnsmith.doma in.com)

                        Comment

                        • Joe90

                          #13
                          Re: trim

                          how ironic $SERVER_NAME worked..

                          "Joe90" <boy_bandreject REMOVE@hotmail. com> wrote in message
                          news:d5ed1r$l9d $1@nwrdmz03.dmz .ncs.ea.ibs-infra.bt.com...[color=blue]
                          > there has to be another way.. I am sure you can do it with Expression, but
                          > I just cant master it. The whole script relies on just being able to pull
                          > just the hostname.
                          >
                          >
                          > "Jason F." <jason.newsonly @gmail.com> wrote in message
                          > news:J_wee.1631 7$n93.12335@twi ster.nyc.rr.com ...[color=green]
                          >> Joe90 wrote:[color=darkred]
                          >>> ^[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$
                          >>>
                          >>> should work ok even with .co.uk :-)
                          >>>
                          >>> however how would I extract just the domain part, in the case of
                          >>> thisisasub.doma in.com , www.domain.com or what if it was just domain.com
                          >>> the script would have to be adaptable to all these scenarios.[/color]
                          >>
                          >> If you can't be 100% sure what the intended "base domain" is, then do
                          >> what many scripts do and simply make it a configuration option.
                          >>
                          >> e.g. You can use wildcard DNS for domains such as
                          >> http://anything.goes.here.dev.basedomain.com, and there's no easy way to
                          >> know that "anything.goes. here" is the intended host part and
                          >> "dev.basedomain .com" is the base part just by looking at HTTP_HOST or
                          >> SERVER_NAME.[/color]
                          >
                          >[/color]


                          Comment

                          Working...