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

  • Home
  • SEARCH
  • 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 4059840
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:15:37+00:00 2026-05-20T15:15:37+00:00

I have an array of data I’m iterating through containing a Title and a

  • 0

I have an array of data I’m iterating through containing a Title and a Description. Each description currently begins with the corresponding title, so I want to ltrim() it off. Unfortunately, not all Titles were written in the same case format as used at the beginning of the description. I was going to use:

ltrim($description,$title)

but the case problem has stopped that.

Data EG:

array(
    array("title" => "Hello World", "description" => "Hello World This is a description"),
    array("title" => "Hellow world", "description" => "Hellow World This is a description"),
    array("title" => "Hello again", "description" => "HELLO AGAIN This is a description"));

ltrim($description,$title) would clean the first, but leave the others alone.

I didn’t create the data I’m cleaning up btw, I’ve just taken over the job.

Anyway, ltrim() is case-sensitive (yes?) so I’m at abit of a loss as to how to go about this. Is there any other way of doing this?

edit

Forgot to mention, the Title DOESN’T ALWAYS appear in the description, just 90% of the time

  • 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-20T15:15:38+00:00Added an answer on May 20, 2026 at 3:15 pm

    ltrim is not the function you want in the first place. The second argument to ltrim is a charlist, so it will keep removing from the left of the string as long as one of the characters is encountered.

    If every title is in every description you could use str_ireplace. And replace the title with nothing, and set the count to 1.

    The better alternative is to use regular expressions.

    preg_replace('/^'.preg_quote($title, '/').'\s*/i', '', $description);
    

    This will replace the title if it is the first thing in the description, followed by any whitespace (so spaces/newlines will be removed if they come after the title. preg_quote is important to protect the regular expression incase the title contains any regex characters.

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

Sidebar

Related Questions

I have CSV data loaded into a multidimensional array. In this way each row
I have an array: data.Dealer.car[0] data.Dealer.car[1] data.Dealer.car[2] If I do this: alert(data.Dealer.car.length); delete data.Dealer.car[1];
I'm looking for a kind of array data-type that can easily have items added,
I have an array of a few million numbers. double* const data = new
I have a two dimensional array that I need to load data into. I
I have a two-dimensional array (of Strings) which make up my data table (of
I have a class 'Data' that uses a getter to access some array. If
I have a big lump of binary data in a char[] array which I
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
serial.write() method in pyserial seems to only send string data. I have arrays like

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.