-1

I am triyng to replace 2 or more newlines with just 1 using PHP's preg_replace() function

$entry = preg_replace('/\n{2,}/', '\n', $entry);

However it replaces it with a "\n" instead of a newline. I mean, it sees \n as a normal string with two letters. What should i do?

kai
  • 13
  • 7

1 Answers1

0

In php, there are some differences between double quotes and single quotes: PHP: different quotes?. To answer your question, all you need to do is replace the single quotes with double quotes as shown here:

$entry = preg_replace('/\n{2,}/', "\n", $entry);

You can read all about strings in php in the documentation: https://secure.php.net/manual/en/language.types.string.php

KingCoder11
  • 415
  • 4
  • 19