/    Sign up×
Community /Pin to ProfileBookmark

detect characters in variable

Hello,

I want to add ‘http://’ to a link if someone types in starting with ‘www.’ , that information is stored in variable $test. How do i detect if $test is starting with ‘www.’ ?

Thanks for any help!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@YelgnidrocAug 27.2007 — if (preg_match('/^www./',$test)) $test="http://".$test;

echo $test;
Copy linkTweet thisAlerts:
@YelgnidrocAug 27.2007 — PS you might also want to do a better regex to check that a valid url has been entered, rather than relying on it being something starting www. as www. on it's own passes this test. :rolleyes:
Copy linkTweet thisAlerts:
@koolaidauthorAug 28.2007 — PS you might also want to do a better regex to check that a valid url has been entered, rather than relying on it being something starting www. as www. on it's own passes this test. :rolleyes:[/QUOTE]

Alright thanks for giving me start, i am fairly new to PHP, so how would i check the whole URL instead of assuming it starts on www. ?
Copy linkTweet thisAlerts:
@YelgnidrocAug 28.2007 — What / how you check depends on what you are doing.

A good start which would also help you get up to speed would be to google

regex url validation
×

Success!

Help @koolaid spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...