Possible Duplicate:
PHP startsWith() and endsWith() functions
Check if variable starts with ‘http’
How make an if-statement that if $mystring has the prefix "http://" then {do something}.
I've done this in objective-c like this:
if([mynsstring hasPrefix:@"http://"])
{
//Do something...
}
I don't know how to do this in PHP. Thanks for your help in advance.
asked Nov 1, 2012 at 18:59
atomikpanda
1,8865 gold badges35 silver badges48 bronze badges
-
1php.net/strings - in PHP the string library is a list of functions, that might be different from string objects in objective C.hakre– hakre2012年11月01日 19:10:20 +00:00Commented Nov 1, 2012 at 19:10
1 Answer 1
Simplest would be using substring to compare
if (substr($mystring, 0, 7) === 'http://') {
// do something
}
Remember of course to take the exact number of characters.
matpop
1,5161 gold badge22 silver badges38 bronze badges
answered Nov 1, 2012 at 19:02
benedict_w
3,6282 gold badges35 silver badges51 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
default