This is driving me nuts, it keeps returning 0
substr_count('df
d
fd
f
df', '\n');
if I use a letter like "d", it works fine
substr_count('df
d
fd
f
df', 'd');
Can anyone shed some light on this?
Thanks
This is driving me nuts, it keeps returning 0
substr_count('df
d
fd
f
df', '\n');
if I use a letter like "d", it works fine
substr_count('df
d
fd
f
df', 'd');
Can anyone shed some light on this?
Thanks
In addition to Alix and Mark: please use
PHP_EOL
instead of\n
. Newlines differ on the different platforms (Windows/Linux/Mac), butPHP_EOL
is always right. See this question for more info on the subject: When do I use the PHP constant "PHP_EOL"?'\n' is not the same as "\n". '\n' is text comprising a slash and the letter "n", whereas "\n" is a newline character.
Suggest you read the relevant section of the PHP manual about strings, particularly where it talks about single and double quoted strings.
You need to use double quotes for control characters: