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, is enterrd in the form http// is added to the datebase
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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 ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
perhaps a simple replacement like this?

$url = "";

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

echo $url;

Open in new window

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

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


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

Open in new window

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.
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!!
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

From novice to tech pro — start learning today.