GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Jul-2007, 07:17
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

How to strip http:// from a form entry


Hello,

I have a form that I use to allow users to enter webcams to the database on my website. I want to be able to strip out the 'http://' from the web address entered.

Can anyone help me.

Thanks,
Richard

http://thewebcamsite.net
  #2  
Old 15-Jul-2007, 08:15
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 733
admin will become famous soon enough

Re: How to strip http:// (scheme) from a form entry


The SIMPLEST method would be to use str_replace() on the string, but that would be reckless.

You also want to consider secure urls with https://.

A function that can work with all the protocols will be a wiser choice, maybe something like this:

PHP Code:

<?php
function strip_scheme_from_url( $url )
{
    $tmp = parse_url( $url );
    if( isset($tmp['scheme']) )
        $url = preg_replace( "~$tmp[scheme]://~i", null, $url, 1 );
        
    return $url;
}

$url = 'ftp://ftp.example.com/';

echo strip_scheme_from_url( $url );
?>


Example code above not tested extensively.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
 
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML Form to PHP File - Help Requested vigilantweather MySQL / PHP Forum 15 07-Aug-2006 19:22
Binary Search Tree penance C Programming Language 2 07-Aug-2005 04:37
PHP form needs validation jabesign MySQL / PHP Forum 16 05-Jan-2005 00:23
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 03:38
help with form orbitel MySQL / PHP Forum 11 21-Jan-2004 15:29

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:45.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.