How to detect if a string has a new line break in it?

前端 未结 3 1219
旧时难觅i
旧时难觅i 2021-02-02 08:17

This doesn\'t work:

$string = \'Hello
    world\';

if(strpos($string, \'\\n\')) {
    echo \'New line break found\';
}
else {
    echo \'not found\';
}
<         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-02-02 08:29

    line break is \r\n on windows and on UNIX machines it is \n. so its search for PHP_EOL instead of "\n" for cross-OS compatibility, or search for both "\r\n" and "\n".

提交回复
热议问题