SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast thomasfrank09's Avatar
    Join Date
    Jun 2009
    Location
    Ames, IA
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I delete text out of a string?

    I'm writing a function that will return the host of a domain name using php's parse_url function. It takes in an array of domain names and returns the TLD for each one. I've already gotten it to add "http://" to each domain, but some of the domains in the array end in a period (as they can) - the problem is, parse_url doesn't recognize the url if this period is there. How can I delete the period? Here's my code for the function so far...

    PHP Code:
    <?php

    $domains 
    = array('iastate.edu''www.google.com''w3.org.''www.deutschland.de''www.bbcnews.co.uk.');

    print_r ($domains);

    echo 
    "<br />";

    foreach (
    $domains as &$name) {

    $name "http://" $name;

    $parsed_url parse_url($name);

    $hostname explode('.' $parsed_url[host]);

    $count count($hostname) - 1;
        
    $name $hostname[$count];

    }

    print_r ($domains);

    ?>
    I run the blog College Info Geek.

    You can find me at:
    My personal site | Facebook | Twitter | LinkedIn

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,060
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    PHP Code:
    $name rtrim("http://" $name'.'); 
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •