-2

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
1
  • 1
    php.net/strings - in PHP the string library is a list of functions, that might be different from string objects in objective C. Commented Nov 1, 2012 at 19:10

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.