[SOLVED] appending characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

[SOLVED] appending characters

Post by $var »

hello,

how would i go about adding a string to an entry, only if it doesn't exist already.
on entering a URL in a member field, i have found most people prefer to omit http://
which just comes up as http://www.mydomain.com/www.theirdomain.com and returning a 404.

how i do i go about automatically adding the http:// if they don't... and only if they don't?
Last edited by $var on Thu Oct 27, 2005 2:27 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

prepending http:// can be done via simply looking at the output of strpos() to make sure http:// is the first part of the string. If it fails or is later in the string

Code: Select all

$url = 'http://' . $url;
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

thank ya!
Post Reply