我有一个字符串,我从数据库中检索,我想计算字符串的长度没有空格,但它显示一个较大的长度值(比实际计数大21个字符)I已经删除了标签和换行符以及php和html标签,但没有结果!我已经尝试了几乎w3schools php参考的所有功能,但是我无法找到任何成功。我还观察到,如果我不从数据库中检索输入值这样的:Strlen没有给出正确的输出
$string = "my string";
我得到正确的长度,请帮助我。下面是代码:
if($res_tutor[0]['tutor_experience']){
$str = trim(strip_tags($res_tutor[0]['tutor_experience']));
$str = $this->real_string($str);
$space = substr_count($str, ' ');
$experience = strlen($str) - $space;
function real_string($str)
{
$search = array("\t","\n","\r\n","\0","\v");
$replace = array('','','','','');
$str = str_replace($search,$replace,$str);
return $str;
}
这是从数据库中字符串,但你可以看到上面我已删除了使用strip_tags()
所有php和html标签:
<span class=\"experience_font\">You are encouraged to write a short description of yourself, teaching experience and teaching method. You may use the guidelines below to assist you in your writing.<br />
<br />
.Years of teaching experience<br />
.Total number of students taught<br />
.Levels & subjects that you have taught<br />
.The improvements that your students have made<br />
.Other achievements/experience (Relief teaching, a tutor in a tuition centre, Dean's list, scholarship, public speaking etc.)<br />
.For Music (Gigs at Esplanade, Your performances in various locations etc.)</span><br />
</p>
,当我打印出来,它显示为:
<span class=\"experience_font\">You are encouraged to write a short description of yourself, teaching experience and teaching method. You may use the guidelines below to assist you in your writing.<br />
<br />
.Years of teaching experience<br />
.Total number of students taught<br />
.Levels & subjects that you have taught<br />
.The improvements that your students have made<br />
.Other achievements/experience (Relief teaching, a tutor in a tuition centre, Dean's list, scholarship, public speaking etc.)<br />
.For Music (Gigs at Esplanade, Your performances in various locations etc.)</span><br />
</p>
如果您正在浏览器中查看,请确保没有任何html标签以及其中的内容。只是因为你看不到多余的字符意味着很少。 –
有额外的标签,我已经删除了使用strip_tags() – irohit786
我不明白...我用你输入的输入运行你的代码,它对我来说工作正常。它必须与你从db得到的东西有关......你需要添加更多的代码,尝试从db直接复制文本或类似的东西。 – hummingBird