Note that there are some explanatory texts on larger screens.

plurals
  1. POStrlen is not giving correct output
    primarykey
    data
    text
    <p>I have a string which I retrieve from a database, I want to calculate the length of the string without spaces but it is displaying a larger value of length(21 characters greater than the actual count) I have removed tab and newline characters and also the php and html tags but no result! I have tried almost every function on the w3schools php reference but I'm unable to find any success. I also have observed that if I don't retrieve the value from the database and input it like this:</p> <p><code>$string = "my string";</code></p> <p>I get the correct length, please help me. Here is the code:</p> <pre><code>if($res_tutor[0]['tutor_experience']){ $str = trim(strip_tags($res_tutor[0]['tutor_experience'])); $str = $this-&gt;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; } </code></pre> <p>And this is the string from the database but as you can see above I have removed all php and html tags using <code>strip_tags()</code> :</p> <pre><code>&lt;span class=\"experience_font\"&gt;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.&lt;br /&gt; &lt;br /&gt; .Years of teaching experience&lt;br /&gt; .Total number of students taught&lt;br /&gt; .Levels &amp;amp; subjects that you have taught&lt;br /&gt; .The improvements that your students have made&lt;br /&gt; .Other achievements/experience (Relief teaching, a tutor in a tuition centre, Dean&amp;#39;s list, scholarship, public speaking etc.)&lt;br /&gt; .For Music (Gigs at Esplanade, Your performances in various locations etc.)&lt;/span&gt;&lt;br /&gt; &amp;nbsp;&lt;/p&gt; </code></pre> <p>and when I print it, it displays as:</p> <pre><code>&lt;span class=\"experience_font\"&gt;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.&lt;br /&gt; &lt;br /&gt; .Years of teaching experience&lt;br /&gt; .Total number of students taught&lt;br /&gt; .Levels &amp;amp; subjects that you have taught&lt;br /&gt; .The improvements that your students have made&lt;br /&gt; .Other achievements/experience (Relief teaching, a tutor in a tuition centre, Dean&amp;#39;s list, scholarship, public speaking etc.)&lt;br /&gt; .For Music (Gigs at Esplanade, Your performances in various locations etc.)&lt;/span&gt;&lt;br /&gt; &amp;nbsp;&lt;/p&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload