我有一個字符串,我從數據庫中檢索,我想計算字符串的長度沒有空格,但它顯示一個較大的長度值(比實際計數大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