spires Posted April 16, 2008 Share Posted April 16, 2008 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 More sharing options...
rhodesa Posted April 16, 2008 Share Posted April 16, 2008 First thing I notice is that this line needs double quotes, not single quotes: $text = $text_area_1.'\r\n'.$text_area; should be: $text = $text_area_1."\r\n".$text_area; Single quotes doesn't evaluate those special characters Link to comment https://forums.phpfreaks.com/topic/101402-solved-line-break/#findComment-518633 Share on other sites More sharing options...
benphp Posted April 16, 2008 Share Posted April 16, 2008 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 More sharing options...
spires Posted April 16, 2008 Author Share Posted April 16, 2008 Perfect :-) Link to comment https://forums.phpfreaks.com/topic/101402-solved-line-break/#findComment-518645 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.