concatenate a form file with static characters

Having a blonde momment ...

Example I want to add http:// to the  data entered in the field url so if www,abctools.com is enterrd in the form http//www.abctools.com is added to the datebase
DDeanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
perhaps a simple replacement like this?

$url = "http://www.abctools.com";

if (substr($url, 0, 7) != "http://") {
	$url = "http://" + $url;
}

echo $url;

Open in new window

0
hieloCommented:
assuming you have the domain/url in $_POST['url'], then
$url = "http://{$_POST['url']}";

will prefix the domain with 'http://'
0
Martin FernandezCommented:
Whenever you want to concatenate something you can easily do that with a dot (".").

i.e:

$url = 'http://' . $_POST['url'];

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
At one level, string concatenation is the "right" answer here (cf: Useful functions and operators), but there is an increasing possibility that http:// might be the wrong thing to prepend to the URL path.  Every WWW authority is currently and correctly recommending that the HTTPS protocol should be used instead of HTTP.  You might want to take this into consideration and come up with a strategy to determine which protocol is right.  You might not want to store the wrong protocol in your database, or you might want a strategy to review and correct the protocols.
0
DDeanAuthor Commented:
There were 3 good selection, but Ray, yours was the simplest one. As soon as I saw it my blonde moment went completely away!!
THANK YOU
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.