Wednesday 28 November 2018

objective c - string has prefix PHP











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.


Answer



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.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...