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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:29:24+00:00 2026-06-08T05:29:24+00:00

Sorry for the title, I really didn’t know how to say this… I often

  • 0

Sorry for the title, I really didn’t know how to say this…

I often have a string that needs to be cut after X characters, my problem is that this string often contains special characters like : & egrave ;

So, I’m wondering, is their a way to know in php, without transforming my string, if when I am cutting my string, I am in the middle of a special char.

Example

This is my string with a special char : è - and I want it to cut in the middle of the "è" but still keeping the string intact

so right now my result with a sub string would be :

This is my string with a special char : &egra

but I want to have something like this :

This is my string with a special char : è
  • 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-08T05:29:26+00:00Added an answer on June 8, 2026 at 5:29 am

    The best thing to do here is store your string as UTF-8 without any html entities, and use the mb_* family of functions with utf8 as the encoding.

    But, if your string is ASCII or iso-8859-1/win1252, you can use the special HTML-ENTITIES encoding of the mb_string library:

    $s = 'This is my string with a special char : è - and I want it to cut in the middle of the "è" but still keeping the string intact';
    echo mb_substr($s, 0, 40, 'HTML-ENTITIES');
    echo mb_substr($s, 0, 41, 'HTML-ENTITIES');
    

    However, if your underlying string is UTF-8 or some other multibyte encoding, using HTML-ENTITIES is not safe! This is because HTML-ENTITIES really means “win1252 with high-bit characters as html entities”. This is an example of where this can go wrong:

    // Assuming that é is in utf8:
    mb_substr('é ', 0, 2, 'HTML-ENTITIES') === 'é'
    // should be 'é '
    

    When your string is in a multibyte encoding, you must instead convert all html entities to a common encoding before you split. E.g.:

    $strings_actual_encoding = 'utf8';
    $s_noentities = html_entity_decode($s, ENT_QUOTES, $strings_actual_encoding); 
    $s_trunc_noentities =  mb_substr($s_noentities, 0, 41, $strings_actual_encoding);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the vague title but I really didn't know what title to give
(Sorry for the title, I don't really know how to phrase that :-) )
Sorry for the poor title, I don't really know what to call this. I
I really didnt know what to put to the title so sorry about that.
Sorry, I really don't know how to summarize the title of this question. So,
Sorry about the vague title, but I really don't know how to describe this
Sorry for the poor title. I really have no idea how to describe this
Didn't know how to word the title sorry. Basically I have a comments system,
I am sorry for the title but I really do not know how to
Sorry for the vague title, as I really can't explain this problem succinctly. Basically

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.