I'm new to PHP, but I have some experiences with C and assembler. So I'm always concerned about the execution. Although these things do not affect one single operation but it could be interesting if you consider them for the whole project:

So what is faster:
$str = "abcdefgh..."; or
$str = 'abcdefgh...';
The first is scanned for included variables, the second not, as far as I know. But I saw a lot of code where always " " is used.

and:
$str = "$str1$str2"; or
$str = $str1 . $str2;

How do I check if one string is the beginning of another string?

A regular expression or:
strncmp ($str1, $str2, strlen($str2));

I could do tests, but maybe somebody already has done these. Maybe parsing the code is by far more time consuming then any of the operations above. But in loops...

Thanx
nòóx

    to:
    strncmp ($str1, $str2, strlen($str2));

    Just read in the manual, that strncmp(str1, str2, len) compares not more then len characters. But if one string is shorter then len, only the length of this string is compared.

    So you have to set len to the maximum length the string could have.

      Write a Reply...