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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:13:57+00:00 2026-05-31T10:13:57+00:00

I have strings like these: my value1 => my value1 my Value2 => my

  • 0

I have strings like these:

"my value1" => my value1
"my Value2" => my Value2
myvalue3 => myvalue3 

I need to get rid of " (double-quotes) in end and start, if these exist, but if there is this kind of character inside String then it should be left there. Example:

"my " value1" => my " value1

How can I do this in PHP – is there function for this or do I have to code it myself?

  • 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-31T10:13:59+00:00Added an answer on May 31, 2026 at 10:13 am

    The literal answer would be

    trim($string,'"'); // double quotes
    trim($string,'\'"'); // any combination of ' and "
    

    It will remove all leading and trailing quotes from a string.

    If you need to remove strictly the first and the last quote in case they exist, then it could be a regular expression like this

    preg_replace('~^"?(.*?)"?$~', '$1', $string); // double quotes
    preg_replace('~^[\'"]?(.*?)[\'"]?$~', '$1', $string); // either ' or " whichever is found
    

    If you need to remove only in case the leading and trailing quote are strictly paired, then use the function from Steve Chambers’ answer

    However, if your goal is to read a value from a CSV file, fgetcsv is the only correct option. It will take care of all the edge cases, stripping the value enclosures as well.

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

Sidebar

Related Questions

I have a string like val1_val2,val3_val4 and I need to split these values to
I have a string that looks like this: Name1=Value1;Name2=Value2;Name3=Value3 Is there a built-in class/function
I have strings like: Avery® Laser & Inkjet Self-Adhesive I need to convert them
I have a String: "{key1:value1}{key2:value2}" . I want to split these string using regular
I have a string exactly like that: <info> <m_album>value1</m_album> <m_cat>value2</m_cat> <cat_type/> <cat_permission>0</cat_permission> <m_img_thumb><!--[CDATA[urlvaluetoimage]]--></m_img_thumb> <m_img_medium><!--[CDATA[urlvaluetoimage]]--></m_img_medium>
I have several strings which contain numberic values. I'd like to format these strings
I have an array like this: myarray = ['value1','value2','value3'] And I'm looking for a
I have a string that looks like: key1/value1/key2/value2/ and so on I did an
I have a string like this: key1\value1\key2\value2\key3\value3\key4\value4\key5\value5 And I'd like it to be an
I have a class that contains two methods like these: public String getFoo(Int32 a)

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.