Results 1 to 7 of 7
  1. #1
    joliett89 is offline Sophomore
    Join Date
    Aug 2011
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

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

    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.

  2. #2
    SEO Consult is offline Freshman
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post
    Feedback Score
    0

    Default

    Lets see if I understand you here. You want to take bloginfo("url") and strip off some text?

    You can use str_replace(arg1,arg2,arg3). It has 3 arguments.

    arg1 = the string to replace, put this in quotes
    arg2 = the string to replace it with, put this in qoutes
    arg3 = the string you are searching and replacing text within, in this case bloginfo("url")

    str_replace("something","",bloginfo("url"));

    will simply strip "something" and replace it with nothing.

    You'll need

    <?php echo str_replace("something","",bloginfo("url")); ?>

    You can find more info on the PHP website and searching for str_replace.

    Hope that helps!

    Andy at SEO Consult

  3. #3
    PK-Host is offline Freshman
    Join Date
    Apr 2012
    Location
    England
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

    Default

    PHP Code:
    <?php echo str_replace("h t t p : / /","",bloginfo("url")); ?>
    That should work I think. However by the looks of it the bloginfo function echos out its output. You may have to find that function and change echo to return.

  4. #4
    johnny04 is offline Junior
    Join Date
    Feb 2012
    Posts
    198
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Feedback Score
    0

    Default

    this seems to be WordPress..

    you cannot use bloginfo() inside a str_replace because bloginfo() doesn't return anything it will just echo the requested data. you need to use get_bloginfo() instead..

    PHP Code:
    <a href="<?php bloginfo('url'); ?>"><?php str_replace("http://"""get_bloginfo('url')); ?></a>

  5. #5
    jdilegge's Avatar
    jdilegge is offline Freshman
    Join Date
    Jul 2012
    Location
    Nashville, TN, USA
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

    Default

    Quote Originally Posted by PK-Host View Post
    PHP Code:
    <?php echo str_replace('h t t p : / /','',$anyvariablehere); ?>
    That should work I think. However by the looks of it the bloginfo function echos out its output. You may have to find that function and change echo to return.
    Also note to remove the spaces in H T T P : / /
    I have specialized in LAMP and much more with the US Navy and various corporations.
    See my tutorial site in the re-making at http://crackfeed.com/

  6. #6
    Join Date
    Mar 2012
    Posts
    681
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

  7. #7
    Join Date
    Mar 2012
    Posts
    681
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

Similar Threads

  1. Replies: 0
    Last Post: 11-06-2011, 12:58 PM
  2. Replies: 0
    Last Post: 10-31-2011, 08:19 AM
  3. Replies: 0
    Last Post: 10-22-2011, 12:37 PM
  4. Replies: 0
    Last Post: 10-15-2011, 02:52 PM
  5. Replies: 1
    Last Post: 09-08-2011, 10:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Partners: BOSTON WEB DEVELOPER, LLC   |   WEBCOSMO CLASSIFIEDS