Question

function countCharacterNoCK($contentVar, $maximumChars){

        $countThisString = strip_tags($contentVar);

        $umlaute = Array("/ä/","/ö/","/ü/","/Ä/","/Ö/","/Ü/","/ß/");
        $replace = Array("a","o","u","A","O","U","s");
        $countThisString1 = preg_replace($umlaute, $replace, $countThisString);

        $lenght = mb_strlen(html_entity_decode($countThisString1, ENT_QUOTES, 'UTF-8'));

        if($lenght < $maximumChars+1){
            return TRUE;
        }else{
            return $lenght;
        }
}

This function doesn´t work as expected. Problem is: I´ve got a <textarea>, in which i can Press Enter.

<textarea name="testvalue">
12345 1234
1234512345
</textarea>

if i call my function $test = countCharacterNoCK($_POST['testvalue'], 20); it´ll return "22".

How to solve this? I´ve tried it with strip_tags but it didn´t solve my problem...I want the function to count like MS Office (Word), but can´t get this solved...any tipps?

Was it helpful?

Solution

i guess that it is counting the invisible character of new lines '\n'.

you should try trim first that instead

$temporarystring =trim($countThisString1);
$lenght = mb_strlen(html_entity_decode($temporarystring, ENT_QUOTES, 'UTF-8'));

OTHER TIPS

The whole day i searched, and now after i asked the question i found the solution:

$umlaute = Array("/ä/","/ö/","/ü/","/Ä/","/Ö/","/Ü/","/ß/",**"~[\r\n]+~"**);
$replace = Array("a","o","u","A","O","U","s",**""**);

Thanks for reading everyone

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top