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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:47:57+00:00 2026-06-11T00:47:57+00:00

I have a string, it is a dog How to remove the starting blanks

  • 0

I have a string,

"

     it is a dog"

How to remove the starting blanks and the new lines?
The output should be:

"it is a dog"

I have tried preg_replace("/^\s*/ms", "", $string), but not works.

  • 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-11T00:47:59+00:00Added an answer on June 11, 2026 at 12:47 am

    Use trim.

    examples from php.net:

    $text   = "\t\tThese are a few words :) ...  ";
    $binary = "\x09Example string\x0A";
    $hello  = "Hello World";
    var_dump($text, $binary, $hello);
    
    print "\n";
    
    $trimmed = trim($text);
    var_dump($trimmed);
    
    $trimmed = trim($text, " \t.");
    var_dump($trimmed);
    
    $trimmed = trim($hello, "Hdle");
    var_dump($trimmed);
    
    $trimmed = trim($hello, 'HdWr');
    var_dump($trimmed);
    
    // trim the ASCII control characters at the beginning and end of $binary
    // (from 0 to 31 inclusive)
    $clean = trim($binary, "\x00..\x1F");
    var_dump($clean);
    

    The above example will output:

    string(32) "        These are a few words :) ...  "
    string(16) "    Example string
    "
    string(11) "Hello World"
    
    string(28) "These are a few words :) ..."
    string(24) "These are a few words :)"
    string(5) "o Wor"
    string(9) "ello Worl"
    string(14) "Example string"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string such as big bad dog, how can I get an
I have the following function: func addCatsToMap(m map[string][]CatHouse, meowId int, treats Set, dog *Dog)
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
Let's say that I have string: -dog--cat--d-- I would like to find all words
I have string like this: dog dog maddog Also I have following regex: [dog]*
I have a String with an unknown length that looks something like this dog,
Possible Duplicate: Replace only first match using preg_replace I have a string as follows:
Suppose I have string variable: var animals = catdog caT dog cat; I don't
I have a string as follows : Panther^Pink,Green,Yellow|Dog^Hot,Top This string means I have 2
I have a string which may or may not end with whitespace and I'm

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.