20i Reseller Hosting

landing page to use google fonts.

Discussion in 'Mini Sites' started by SecNam, Oct 3, 2013.

Thread Status:
Not open for further replies.
  1. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,188
    Likes Received:
    43
    Hi, i am hoping someone can help/advise.

    At the moment i am using the following code to grab the url and display it on a page:


    <?
    $domainstart = $_SERVER['HTTP_HOST'];
    $domainname = str_replace("www.", "", "$domainstart");
    ?>

    then on the page this displays the domain name:

    <? echo "$domainname"; ?>

    What i am trying to do is when <? echo "$domainname"; ?> shows the url how do i go about it using google fonts.

    thanks in advance.
     
  2. Domain Forum

    Acorn Domains Elite Member

    Joined:
    1999
    Messages:
    Many
    Likes Received:
    Lots
    articles.co.uk
     
  3. Edwin

    Edwin Well-Known Member Exclusive Member

    Joined:
    Apr 2005
    Posts:
    9,815
    Likes Received:
    537
    Let's take a random example...

    <link href='http://fonts.googleapis.com/css?family=Kite+One' rel='stylesheet' type='text/css'>

    Put the above between the <head> and </head> tags

    Then use the following:

    <?
    echo "<p style=\"font-family: 'Kite One', sans-serif;\">".$domain."</p>";
    ?>

    You can also use a <span></span> instead of the <p></p> if you don't want to put the domain within a new paragraph.

    The \ in front of the " tells PHP to display the " as a symbol, rather than process it i.e. you have to put that so that you don't drop out of the string being echo-ed.
     
  4. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,188
    Likes Received:
    43
    Thanks edwin, I tried the above but doesnt seem to work. I have a good dig around the net tonight to see if it is achievable.
     
  5. Edwin

    Edwin Well-Known Member Exclusive Member

    Joined:
    Apr 2005
    Posts:
    9,815
    Likes Received:
    537
    Can you be more specific? What do you see on the screen? What error message (if any)? I've not tested the above so I may have misplaced a punctuation mark, or similar...
     
  6. Admin

    Admin Administrator Staff Member

    Joined:
    Jun 2004
    Posts:
    10,803
    Likes Received:
    294
    It's $domainname not $domain

    Admin
     
  7. Admin

    Admin Administrator Staff Member

    Joined:
    Jun 2004
    Posts:
    10,803
    Likes Received:
    294
    Code:
    <head>
    <link href='http://fonts.googleapis.com/css?family=Kite+One' rel='stylesheet' type='text/css'>
    </head>
    <?php
    $domainstart = $_SERVER['HTTP_HOST'];
    $domainname = str_replace("www.", "", "$domainstart");
    echo "<div style=\"font-family: 'Kite One', 'sans-serif';\">".$domainname."</div>";
    ?>
    Full code above, works for me

    Admin
     
  8. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,188
    Likes Received:
    43
    <p style="font-family: 'Parisienne', serif;\"><font size="7"><? echo "$domainname."; ?></font>
     
  9. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,188
    Likes Received:
    43
    yeah cheers admin above is the code that works. Thanks edwin and admin for taking the time to put me on the right track.
     
  10. Edwin

    Edwin Well-Known Member Exclusive Member

    Joined:
    Apr 2005
    Posts:
    9,815
    Likes Received:
    537
    Oops, yeah. Thanks.
     
  11. martin-s United Kingdom

    martin-s Well-Known Member

    Joined:
    Jul 2012
    Posts:
    3,339
    Likes Received:
    226
    If you like nice fonts, can thoroughly recommend typekit.com to do a similar job to a higher standard :)
     
  12. SecNam

    SecNam Moderator Staff Member

    Joined:
    Jul 2004
    Posts:
    5,188
    Likes Received:
    43
    going back to the above small script, it dispays the domain name on the website for example thisdomainname.co.uk

    can anyone help in having it strip out the extension so it only displays thisdomainname

    thanks in advance.
     
  13. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,658
    Likes Received:
    136
    The easiest way to remove the extension (since you know it will only be .co.uk/.org.uk etc) would be use str_replace or strtr with an array of known extensions and replace them all with nothing.

    The regex to detect and remove all known extensions is a ball ache, so if you know the extensions just replace them.
     
  14. seemly

    seemly Well-Known Member

    Joined:
    Feb 2011
    Posts:
    1,224
    Likes Received:
    189
    Assuming you are not on a subdomain (other than www), this script will cater for all domain extensions, without the need for defining and stripping out specific extensions:

    Code:
    <?php  
    $host = str_replace('www.', '', $_SERVER['SERVER_NAME']);
    $parts = explode('.', $host);
    $domain = $parts[0];
    
    echo $domain;
    
    ?>
    
     
    Last edited: Nov 22, 2013
  15. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,658
    Likes Received:
    136
    To get around the issue seemly mentioned about www and other subdomains you would try to catch here, again this would only work with 3rd level domains like .*.uk not with .com and such. Always a limitation with simple things :(

    Code:
    if(sizeof($parts)==2){
    $domain = $parts[0];
    }else{
    $domain = $parts[1];
    }
    
    I have found pretty good traffic coming from sub domains, if your host supports wildcard subdomains you should def set that :)
     
Thread Status:
Not open for further replies.