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

Community
  • 1
  • 1
atomikpanda
  • 1,845
  • 5
  • 33
  • 47
  • 1
    http://php.net/strings - in PHP the string library is a list of functions, that might be different from string objects in objective C. – hakre Nov 01 '12 at 19:10

1 Answers1

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,969
  • 1
  • 19
  • 36
benedict_w
  • 3,543
  • 1
  • 32
  • 49