Jump to content

[SOLVED] line break?


spires

Recommended Posts

Hi Guys

 

I'm trying to do a simple line break, but something is going wrong.

 

all i'm trying to do is:

 

$string1 = 'Campaign, Adgroup, Headline, Body1, Body2, URL, Destination';

$string2 = 'Mobiles, Mobiles, Buy now, cheap, sales, bb.com, bb.com';

 

echo out in a textarea (Also exporting to .cvs file):

$string1

$string2

 

Basically $string 2 starts on a new line.

 

Website: http://www.adwordstool.co.uk/test.php

 

Heres the code

<?php if (!empty($_POST['submit'])) {
$arrErrors = array();
if ($_POST['text']=='') $arrErrors['text'] = 'ERROR';
	if (count($arrErrors) == 0) {
$text_area = $_POST['text'];
$Ftext = 'Campaign, Adgroup, Headline, Body1, Body2, URL, Destination';

$id = '3';
$filename = 'files/'.$id;

if (file_exists($filename)) {


		 $text_area = str_replace("\r\n",",\n",$text_area); 
			$text_area_1 = str_replace("\r\n",",\n",$Ftext); 
			$text = $text_area_1.'\r\n'.$text_area;

			$fp = fopen("files/$id/Advanced.csv", "w");
			fwrite($fp, $text);
			fclose($fp);


} else {
    $dir = mkdir('files/'.$id);

			$text_area_1 = str_replace("\r\n",",\n",$text_area); 
			$fp = fopen("files/$id/Advanced.csv", "w");
			fwrite($fp, $text_area_1);
			fclose($fp);


}



		echo '<a href="http://www.adwordstool.co.uk/files/'.$id.'/Advanced.csv">Download File Now</a><br>';
	}
}?>

<form method="post" action="<?php echo $PHP_SELF; ?>">
<textarea name="text" cols="60" rows="10"><?PHP echo $text; ?></textarea>
<br>
<br><input name="submit" type="submit" value="Submit">
</form>

 

 

Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/101402-solved-line-break/
Share on other sites

Remove one line, and it should work.

$Ftext = 'Campaign, Adgroup, Headline, Body1, Body2, URL, Destination';
$text_area = str_replace("\r\n",",\n",$text_area); //this works 
$text_area_1 = str_replace("\r\n",",\n",$Ftext); //this is the problem, just remove this line
$text = $text_area_1.'\r\n'.$text_area; //this should do what you want.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/101402-solved-line-break/#findComment-518634
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.