Search code examples
phpnewlinestrlenchars

Count number of chars excluding newlines


I'm using strlen() to count the number of chars in a text, but it even counts newline \n. Can i replace newlines is some way to make strlen() don't count them?


Solution

  • use this first replace all new line character by null and than count length.

    echo strlen(str_replace(array("\n", "\r\n", "\r"), '', $string));