WordPress.org

Ready to get started?Download WordPress

Forums

If/else is killing me, something smarter? (2 posts)

  1. Kenneth Jensen
    Member
    Posted 4 years ago #

    Hi there

    Im kinda new to both WordPress and PHP, so this is kinda uphill right now. I managed to do a if-elseif-else that works perfectly, but now im stuck with some more advanced stuff.

    I have a field called ArticleLink. This contains a url either starting with http://, http://www., both or none of them.

    What I would like is a function to do at check and make the outcome a valid url starting with http://www. regardless how it starts

    How do I do that?

    Thanks,
    Kenneth

  2. MichaelH
    Member
    Posted 4 years ago #

    <?php
    $url = 'http://mydomain.com';
    if (strpos($url, '://www.') == false) {
    $url = str_replace('://', '://www.',$url);
    }
    echo '$url is ' . $url;
    ?>

    But here's more where that came from:
    http://core.trac.wordpress.org/ticket/10970#comment:16

Topic Closed

This topic has been closed to new replies.

About this Topic