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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:54:22+00:00 2026-06-05T05:54:22+00:00

i have problem with $length of substr function my CODE $string=’I love stackoverflow.com’; function

  • 0

i have problem with $length of substr function

my CODE

$string='I love stackoverflow.com';
function arabicSubStr($value,$start,$length=false){
    return mb_substr($value,$start,$length,'UTF-8');
}

echo arabicSubStr($string,7);//outputs nothing
echo substr($string,7);//outputs stackoverflow.com

The reason of the problem is:

If length is given and is 0, FALSE or NULL an empty string will be returned.

So, How i can fix the problem?

i won’t use strlen($string)

EDITE

I know the reason is because i’ve defined $length as false

And i am here to know what should i put in $length parameter to avoid this error?

i am trying to put -1 it’s returns //stackoverflow.co

  • 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-05T05:54:25+00:00Added an answer on June 5, 2026 at 5:54 am

    Since the reason you’re getting an empty string is specified entirely by the content of your question (using 0, FALSE or NULL), I assume you just want a way to get the rest of the string.

    In which case, I’d use something like:

    function arabicSubStr ($value, $start, $length = -1) {
        if ($length == -1)
            $length = mb_strlen ($value, 'UTF-8') - $start;
        return mb_substr ($value, $start, $length, 'UTF-8');
    }
    

    You need to do it this way since there is no sentinel value of length that means “the rest of the string”. Positive numbers (and zero) will limit the size to that given, negative numbers will strip off the end of the string (as you show in your question edit).

    If you really don’t want to use a string length function, you could try a value of 9999 (or even higher) and hope that:

    • the mb_substr() function will only use it as a maximum value; and
    • you won’t pass in any strings 10K or more.

    In other words, something along the lines of:

    function arabicSubStr ($value, $start, $length = 9999){
        return mb_substr ($value, $start, $length, 'UTF-8');
    }
    

    Though keep in mind I haven’t tested that, I don’t have any PHP environments at my current location.

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

Sidebar

Related Questions

My problem is a little bit complex. I have the following code: $(document).ready(function() {
I have the following code: private function uploadFile(file:File, packageId:String):void { try { var fullpath:String
Here is the problem: I have a list of items with various length for
I have problem with fancybox. I want to write a function that will run
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have a js code which is displaying Youtube videos. The problem is that
I have problem with encoding data in Oracle database. I want to xor string
I have problem with my code. I don't know what am I doing wrong.
I have the following code. The problem is that neither SELECT nor CANCEL event
I have my replaceAt method look like something from here String.prototype.replaceAt = function(index, c)

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.