Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9074291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:36:03+00:00 2026-06-16T18:36:03+00:00

I have a string which I retrieve from a database, I want to calculate

  • 0

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:

$string = "my string";

I get the correct length, please help me. Here is the code:

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;
}

And this is the string from the database but as you can see above I have removed all php and html tags using strip_tags() :

<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 &amp; 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&#39;s list, scholarship, public speaking etc.)<br />
   .For Music (Gigs at Esplanade, Your performances in various locations etc.)</span><br />
   &nbsp;</p>

and when I print it, it displays as:

<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 &amp; 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&#39;s list, scholarship, public speaking etc.)<br />
   .For Music (Gigs at Esplanade, Your performances in various locations etc.)</span><br />
   &nbsp;</p>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:36:04+00:00Added an answer on June 16, 2026 at 6:36 pm

    @Svetilo, not to be rude just wanted to post my findings, your str_replace worked wonderfully, except for the fact that I was still outputting incorrect values with it in the order that you currently have, I found that the following worked flawlessly.

    $string = str_replace(array("\t","\r\n","\n","\0","\v"," "),'', $string);
    mb_strlen($string, "UTF-8");
    

    Changing around the \r\n & \n made the str_replace not strip out the \n from the \r\n leaving it just a \r.

    Cheers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spinner which I populate from SQLite database. But I want to populate
I have a database which stores value in yyyy-MM-dd HH:mm:ss format. When I retrieve
I have this string of numbers var array = 1,6,2,9,5 which is retrieved from
I have some text data from database that I want to display it on
I have a string in my code which concatenates email addresses from various tables
I have an IList<string> named codes storing the code values for which I want
I have a string which has delimiter in it. I want to know the
I have a string which is of about 1mb size. The requirement is to
I have a string which is in the following format, When there is a
I have a string which varies everytime it is input as it is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.