substr_count not working with new lines?
问题 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 回答1: You need to use double quotes for control characters: var_dump(substr_count('df d fd f df', "\n")); 回答2: '\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