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
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
\nthat 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\nand replace it with a single space.You might want to replace that
\nwith[\r\n]for interoperability.