How can I set any quantity of new lines with a regular expression?
$var = "<p>some text</p><p>another text</p><p>more text</p>";
$search = array("</p>\s<p>");
$replace = array("</p><p>");
$var = str_replace($search, $replace, $var);
I need to remove every new line (\n), not <br/>, between two paragraphs.
To begin with,
str_replace()(which you referenced in your original question) is used to find a literal string and replace it.preg_replace()is used to find something that matches a regular expression and replace it.In the following code sample I use
\s+to find one or more occurrences of white space (new line, tab, space…).\sis whitespace, and the+modifier means one or more of the previous thing.Live Example