Jump to content

Removing multiple line breaks


fagnonk

Recommended Posts

So I am parsing a text file with fopen and I need a way to automatically replace multiple line breaks with single line breaks. Currently, my code simply removes all line breaks but I need a way to allow sinlge line breaks. Is this something I could do with regex? If so, how would I go about it?

<?php
$v1 = $_GET['fileId']; 
$v2 = $_GET['title'];

if (isset($_POST[$v1])) {

$str = $_POST[$v1];

$xml = "".$str."";
        									   
$fp = fopen('cms/'.$v1.'.xml', 'w');

$replace = str_replace(chr(10), " ", $xml); //remove carriage returns
$replace2 = str_replace(chr(13), "", $replace); //remove carriage returns

fwrite($fp, $replace2);
fclose($fp);
}


?>	

Link to comment
https://forums.phpfreaks.com/topic/169557-removing-multiple-line-breaks/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.