ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Adding a prefix to a URL if http:// missing

January 18, 2011 11:53am

Subscribe [2]
  • #1 / Jan 18, 2011 11:53am

    Mediakitchen

    261 posts

    My site includes listings that have a URL field.

    Some people have entered and will enter the website address without the “http://” and therefore when I display these URLs on the site, they do not appear as links.

    I have a php function that can convert a URL without the http:// to one with it. However I am not sure how I can use this with EE.

    function prependMissingProtocol($sURI)
    {
        preg_match('#^https?://#i', $sURI) or ($sURI = 'http://'.$sURI); 
        return $sURI;
    }

    My EE code is as follows:

    {exp:channel:entries channel="services" disable="member_data|trackbacks" limit="1"}
    
         {if website}                
        Website: {website}
    
         {/if}
    
    
    {/exp:channel:entries}

    I haven’t done any work using Expression Engine for a few months now so I am a bit rusty. Anyone tell me how I can process this “website” variable with the PHP function?

    Thanks

    Paul

  • #2 / Jan 18, 2011 12:34pm

    Mediakitchen

    261 posts

    No worries I have found a solution using the auto_linker and the valid_url plugins

    Would be curious if there were any alternative solutions though

    {if website}                
    Website: {exp:auto_linker target="blank"}{exp:valid_url}{website}{/exp:valid_url}{/exp:auto_linker}
    
    {/if}
  • #3 / Jan 19, 2011 1:08am

    John Henry Donovan

    12339 posts

    Mediakitchen,

    A plugin would be the way to go. Even with your own function I would have suggested making it into a plugin. Alternatively you could have used javascript maybe. Closing this one out for now. Feel free to start a new thread if you have any more questions

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases