Best way to strip "http://" in simple PHP code

Discussion in 'PHP' started by joliett89, Jul 1, 2012.

  1. #1
    I have a code like this:

    <div class="left">&copy; <a href="<?php bloginfo('url'); ?>">="<?php bloginfo('url'); ?></a> | <a href="<?php bloginfo('url'); ?>/sitemap_index.xml">Sitemap</a></div>

    , and it is showing the following result:

    C http://domain-name.com | Stemap


    I am wondering if there is any simple way to get rid of "http://" string using PHP ("inline", without using variables etc, like in some tutorials online)


    Thank you.
     
    joliett89, Jul 1, 2012 IP
  2. geforce

    geforce Active Member

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #2
    You could use: str_replace('http://', '', bloginfo('url'))

    Where bloginfo('url') is the string you want to remove the http:// out of.
    Hope it helps :)

    :)
     
    geforce, Jul 1, 2012 IP
  3. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #3
    If you use str_replace, use get_bloginfo instead :) So it will be like this
    
    <div>
    <?php echo str_replace('http://', '', get_bloginfo('url')); ?>
    </div>
    
    PHP:
     
    xrvel, Jul 2, 2012 IP
  4. nanowebtech

    nanowebtech Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    PHP Code:
    <?php str_replace('http://','',bloginfo('url')); ?>
     
    nanowebtech, Jul 2, 2012 IP