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;
}
}
此功能无法正常工作。问题是:我有一个<textarea>
,我可以按Enter键。
<textarea name="testvalue">
12345 1234
1234512345
</textarea>
如果我调用我的函数$test = countCharacterNoCK($_POST['testvalue'], 20);
,它将返回“22”。
如何解决这个问题?我用strip_tags
尝试了它,但它没有解决我的问题......我希望这个功能像MS Office(Word)一样计算,但是不能解决这个问题......任何tipps?
答案 0 :(得分:1)
我猜它是在计算新线条的隐形字符&#39; \ n&#39;。
你应该首先尝试修剪而不是
$temporarystring =trim($countThisString1);
$lenght = mb_strlen(html_entity_decode($temporarystring, ENT_QUOTES, 'UTF-8'));
答案 1 :(得分:0)
我搜索了一整天,现在在我问了问题之后我找到了解决方案:
$umlaute = Array("/ä/","/ö/","/ü/","/Ä/","/Ö/","/Ü/","/ß/",**"~[\r\n]+~"**);
$replace = Array("a","o","u","A","O","U","s",**""**);
感谢您阅读所有人