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 6664933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:40:07+00:00 2026-05-26T02:40:07+00:00

I’m getting � characters when I combine Codeigniter’s character_limiter() with PHP’s native strip_tags() .

  • 0

I’m getting � characters when I combine Codeigniter’s character_limiter() with PHP’s native strip_tags(). Here is the code I’m using:

<?php echo character_limiter(strip_tags($block->body), 60); ?>

$block->body is an HTML string stored in the database. I do not get this unexpected output if I use only one of the functions. It looks like this:

enter image description here

This is what the HTML looks like:

enter image description here

I didn’t paste the actual HTML because the string would be modified by posting it here, see below

Here is the Codeigniter function character_limiter:

function character_limiter($str, $n = 500, $end_char = '&#8230;')
{
    if (strlen($str) < $n)
    {
        return $str;
    }

    $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));

    if (strlen($str) <= $n)
    {
        return $str;
    }

    $out = "";
    foreach (explode(' ', trim($str)) as $val)
    {
        $out .= $val.' ';

        if (strlen($out) >= $n)
        {
            $out = trim($out);
            return (strlen($out) == strlen($str)) ? $out : $out.$end_char;
        }
    }
}

I figured out that there was some invisible character or something that may have been causing this, because when I pasted the HTML into a text editor, then back into the “HTML source editor” in the image (which is just TinyMCE), then saved it, the weird characters disappeared.

I am using the utf-8 character set across the board (everywhere possible). The original data did come from a dump of an unknown database, and was imported with an SQL client. However, when I saved the existing string (in the CMS), nothing changed.

I can’t connect the dots between these two functions causing this output when used together, and I do not get the � characters normally. I only see this output when I use:

character_limiter(strip_tags($html))

What could be causing this, and how can I prevent it?

Note: I definitely want to use the character_limiter function, or a variation of it. It makes an ellipsis at the end of the string if its length is longer than the second param. Using it alone (without strip_tags) works perfectly fine (no weird characters).

Update: For anyone that can’t reproduce this, I put an SQL file online that demos the issue. I am importing this with MySQL Query Browser. I only get this output it seems when the HTML comes from the database. Here is the link (ignore the content, it’s the client’s fault): http://wesleymurch.com/test/test1.sql

  • 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-05-26T02:40:07+00:00Added an answer on May 26, 2026 at 2:40 am

    � replacement character used to replace an unknown or unprintable character
    in php usually we solve this issue using multibyte string functions .
    use mb_substr with strip tags like :

    mb_substr( strip_tags($text) , 0,300 ,'UTF-8' );//or what ever your charset 
    

    or you maybe modify the codeigniter function and use Multibyte String Functions .

    UPDATE

    function character_limiter($str, $n = 500, $end_char = '&#8230;')
    {
        if (mb_strlen($str) < $n)
        {
            return $str;
        }
    
        $str = mb_ereg_replace("\s+", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
    
        if (mb_strlen($str) <= $n)
        {
            return $str;
        }
    
        $out = "";
        foreach (explode(' ', trim($str)) as $val)
        {
            $out .= $val.' ';
    
            if (mb_strlen($out) >= $n)
            {
                $out = trim($out);
                return (mb_strlen($out) == mb_strlen($str)) ? $out : $out.$end_char;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker

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.