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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:24:52+00:00 2026-06-14T22:24:52+00:00

Im asking here again :) Let’s say I have a string in PHP, something

  • 0

Im asking here again 🙂

Let’s say I have a string in PHP, something like this:

Lorem ipsum dolor sit amet, consectetur
adipiscing elit. "Sed et est eget lorem congue
eleifend. Fusce luctus"

Right, so you see the string in those two quote sings —> “, right, if there’s a text, in db, between those two quote signs, it shouldnt have break line like this, is there a way, in regex with preg_replace function in PHP to target break lines inbetween those two symbols and delete them?

Thanks for your time guys,
Mart

  • 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-14T22:24:53+00:00Added an answer on June 14, 2026 at 10:24 pm

    Problems concerning matched or nested elements (in this case matched quotation marks) are usually a bit awkward with regular expressions.

    First, let me make an assumption here: escaped quotation marks inside quotation marks are not allowed in your input (i.e. you never have Lorem "ipsem \" dolor" or something like this).

    With this assumption, your problem boils down to this: find a \n that is followed by an odd number of " (counting until the end of the string). To ensure this condition, we can use a lookahead. To avoid problems with leading or trailing whitespace, we can match any whitespace surround an \n and replace it with a single space.

    $result = preg_replace('/\s*\n\s*(?=[^"]*"(?:[^"]*"[^"]*")*[^"]*$)/', ' ', $input);
    

    You might want to replace that \n with [\r\n] for interoperability.

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

Sidebar

Related Questions

i have asked this question before but no answer was there. so asking again.
today I have been asking here for help with this script . It was
This error is driving me crazy . I tried freenode #emberjs before asking here.
I have seen questions posted on here asking how to left and right align
i dont know if i should be asking this here (im now thinking maybe
This isn't strictly a programming question, but I'm asking it here because it's certainly
I am asking this question here because it is my understanding that this is
this is my first time asking a question here. I tried to be well
here I am again asking for you kind help. I'm working on a GWT
This thread got too confusing (for me) so I am asking the question again.

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.