Hello all.

I have created a simple CMS for a careers section using a "|" delineated txt file to store the content. Basically, using a few form fields I have created the ability to create new, edit and delete each open position. Everything works great...until I implemented the TinyMCE WYSIWIG editor.

Here is what is happening...
- I can create the new position without any issues
- If I edit the position, when I save it, the information is not saved onto one line, but actually is broken up. It seems like the \r\n is being placed after each paragraph/bullet, etc.

Please see the code below and possibly help me out with this issue.

Below is the code for the home CMS page where you are able to create a new position. I don't have any issues with this. Once submitted, the information is written to the txt file as one line with the "|" separation.

Code:
<?php
require_once('FSFPCMS_common.php');
	checkUser();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>FSFP CMS Area</title>
<!-- TinyMCE -->
<script type="text/javascript" src="js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
// Creates a new plugin class and a custom listbox
tinymce.create('tinymce.plugins.ExamplePlugin', {
    createControl: function(n, cm) {
        switch (n) {

        }

        return null;
    }
});
// Register plugin with a short name
tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
// Initialize TinyMCE with the new plugin and listbox
tinyMCE.init({
    plugins : '-example', // - tells TinyMCE to skip the loading of the plugin
    mode : "textareas",
    theme : "advanced",
    theme_advanced_buttons1 : "mylistbox,mysplitbutton,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom"
});
</script>
<!-- /TinyMCE -->
<link href="FSFP.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table bgcolor="#dac2a7" align="center">
<tr>
<td cellpadding="10" cellspacing="10" width="25">
<td cellpadding="10" cellspacing="10" width="600"><br>
<H1><u>First San Francisco Partners Careers CMS</u></H1>
<?
$file = "careers_content.txt"; 
$news = file($file);
echo "<H2><u>Current Positions</u></H2>\n";
foreach ($news as $key => $value) { 
$key = $key-0; 
}
$data = file('careers_content.txt');
//next line removed to make everything else easier in the admin script
//$data = array_reverse($data);
foreach($data as $key=>$element) {
    $element = trim($element);
    $pieces = explode("|", $element);
    echo "<b>" . $pieces[0] . "</b>\n";
    echo " <a href=edit_position.php?id=" . $key . "><font size='1'>Edit</font></a>\n";
    echo " <a href=delete_position.php?id=" . $key . "><font size='1'>Delete</font>\n";
    echo " <a href=position_description.php?id=" . $key . " target='_blank'><font size='1'>View</font></a>\n";
    echo "<BR><BR>\n";
}
echo "<HR>\n";
echo "<H2><u>Add A New Position</u></H2>\n";
if($HTTP_POST_VARS['submit']) {
        if(!$HTTP_POST_VARS['position']) {
            echo "You must enter a Position";
            exit;
        }
        if(!$HTTP_POST_VARS['summary']) {
            echo "You must enter some content for the Position Summary";
            exit;
        }
        if(!$HTTP_POST_VARS['responsibilities']) {
            echo "You must enter some content for Responsibilities";
            exit;
        }
        if(!$HTTP_POST_VARS['requirements']) {
            echo "You must enter some content for Requirements";
            exit;
        }
        if(!$HTTP_POST_VARS['compensation']) {
            echo "You must enter some content for Compensation";
            exit;
        }
        if(!$HTTP_POST_VARS['how']) {
            echo "You must enter some content for How To Apply";
            exit;
        }
        if(strstr($HTTP_POST_VARS['position'],"|")) {
            echo "Position cannot contain the pipe symbol - |";
            exit;
        }
        if(strstr($HTTP_POST_VARS['summary'],"|")) {
            echo "Position Summary cannot contain the pipe symbol - |";
            exit;
        }
        if(strstr($HTTP_POST_VARS['responsibilities'],"|")) {
            echo "Responsibilities cannot contain the pipe symbol - |";
            exit;
        }
        if(strstr($HTTP_POST_VARS['requirements'],"|")) {
            echo "Requirements cannot contain the pipe symbol - |";
            exit;
        }
        if(strstr($HTTP_POST_VARS['compensation'],"|")) {
            echo "Compensation cannot contain the pipe symbol - |";
            exit;
        }
        if(strstr($HTTP_POST_VARS['how'],"|")) {
            echo "How To Apply cannot contain the pipe symbol - |";
            exit;
        }
        $fp = fopen('careers_content.txt','a');
        if(!$fp) {
            echo "Error opening file!";
            exit;
        }
        $line = $HTTP_POST_VARS['position'];
        $line .= "|" . $HTTP_POST_VARS['summary'];
        $line .= "|" . $HTTP_POST_VARS['responsibilities'];
        $line .= "|" . $HTTP_POST_VARS['requirements'];
        $line .= "|" . $HTTP_POST_VARS['compensation'];
        $line .= "|" . $HTTP_POST_VARS['how'];
        $line = str_replace("\r\n","",$line);
        $line .= "\r\n";
        fwrite($fp, $line);
        if(!fclose($fp)) {
            echo "Error closing file!";
            exit;
        }
        echo "<b><font color='#ff0000'>The Position has been added!</font></b> <a href='$PHP_SELF'><font size='1' color='#ff0000'>Refresh the list</font></a><BR><BR>\n";    
    }
?>
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
Position Title:<BR>
<INPUT TYPE="text" SIZE="70" NAME="position"><BR><BR>
Position Summary:<BR>
<TEXTAREA NAME="summary" COLS="70" ROWS="7"></TEXTAREA><BR>
Responsibilities:<BR>
<TEXTAREA NAME="responsibilities" COLS="70" ROWS="7"></TEXTAREA><BR>
Requirements:<BR>
<TEXTAREA NAME="requirements" COLS="70" ROWS="7"></TEXTAREA><BR>
Compensation <font size="1">(We have added default content. You are able to edit this as needed)</font>:<BR>
<TEXTAREA NAME="compensation" COLS="70" ROWS="7">
We offer competitive salary and benefit packages.
</TEXTAREA><BR>
How To Apply <font size="1">(We have added default content. You are able to edit this as needed)</font>:<BR>
<TEXTAREA NAME="how" COLS="70" ROWS="7">
To submit your resume by email:
</TEXTAREA><BR>
&nbsp;
<BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Post it!"><BR>
</FORM>
</td>
<td cellpadding="10" cellspacing="10" width="25">
</tr>
</table>
</body>
</html>
Now here is where I am having the issues:
Below is the code for the edit a position page where you are able to edit an existing position. Basically, the code opens the text file, splits it into an array and places each string into the right form field for editing. Once save/submitted, it seems as if the line breaks are not being removed. For each break, paragraph, bullet, etc. it actually creates a whole new line within the txt file, instead of storing the information is to the txt file as one line with the "|" separation.

Code:
<?php
	require_once('FSFPCMS_common.php');
	checkUser();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CMS Area</title>
<!-- TinyMCE -->
<script type="text/javascript" src="js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
// Creates a new plugin class and a custom listbox
tinymce.create('tinymce.plugins.ExamplePlugin', {
    createControl: function(n, cm) {
        switch (n) {
        }
        return null;
    }
});
// Register plugin with a short name
tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
// Initialize TinyMCE with the new plugin and listbox
tinyMCE.init({
    plugins : '-example', // - tells TinyMCE to skip the loading of the plugin
    mode : "textareas",
    theme : "advanced",
    theme_advanced_buttons1 : "mylistbox,mysplitbutton,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom"
});
</script>
<!-- /TinyMCE -->
<link href="FSFP.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table bgcolor="#dac2a7" align="center">
<tr>
<td cellpadding="10" cellspacing="10" width="25">
<td cellpadding="10" cellspacing="10" width="600"><br>
<H1><u>Careers CMS</u></H1>
<?php
############# begin constants ###################
define("DB_FILE_PATH","careers_content.txt");
define("FILE_ELEMENT_DELIMITER","|");
############# end constants #####################
//check the GET vars, make sure the file exists
if(isset($_GET['id']) && file_exists(DB_FILE_PATH)){
	$lnum = (int)$_GET['id'];//line number as an integer
	//read file lines into array
	$f = file(DB_FILE_PATH,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
	//get the desired line from the array
	@$line = $f[$lnum-0];
	//if there is a line create an array based on the delimiter
	if($line){
		$elems = explode(FILE_ELEMENT_DELIMITER,$line);
	}
	else{
		//that line doesn't exist
		echo "The record with that ID was not found.<br />";
		exit();//done
	}
	if($_SERVER['REQUEST_METHOD'] == "GET"){//show the information if the request is GET
		//prepare the URI to post to
		$action = $_SERVER['PHP_SELF'] . "?id=" . $lnum;
		echo "<form name=\"set_status\" action=\"{$action}\" method=\"post\" >";
    echo "Make the changes you would like and press save.<BR><BR>";
    echo "Position Title:<BR>";
    echo "<INPUT TYPE='text' SIZE='70' NAME='position' value='".$elems[0]."'><BR><BR>";
    echo "Position Summary:<BR>";
    echo "<TEXTAREA NAME='summary' COLS='70' ROWS='7'>".$elems[1]."</TEXTAREA><BR><BR>";
    echo "Responsibilities:<BR>";
    echo "<TEXTAREA NAME='responsibilities' COLS='70' ROWS='7'>".$elems[2]."</TEXTAREA><BR><BR>";
    echo "Requirements:<BR>";
    echo "<TEXTAREA NAME='requirements' COLS='70' ROWS='7'>".$elems[3]."</TEXTAREA><BR><BR>";
    echo "Compensation:<BR>";
    echo "<TEXTAREA NAME='compensation' COLS='70' ROWS='7'>".$elems[4]."</TEXTAREA><BR><BR>";
    echo "How To Apply:<BR>";
    echo "<TEXTAREA NAME='how' COLS='70' ROWS='7'>".$elems[5]."</TEXTAREA><BR><BR>";
		echo '<input type="submit" name="submit" value="Save" /></form>';
	}
	else if($_SERVER['REQUEST_METHOD'] == "POST"){//make the changes, the submit button was pressed
		$elems[0] = $_POST['position'];
		$elems[1] = $_POST['summary'];
		$elems[2] = $_POST['responsibilities'];
		$elems[3] = $_POST['requirements'];
		$elems[4] = $_POST['compensation'];
		$elems[5] = $_POST['how'];
		//set the line, implode each element with the delimiter
		$f[$lnum-0] = implode(FILE_ELEMENT_DELIMITER,$elems);
		//open the file, clear the contents and set the pointer to the beginning
		$nf = fopen(DB_FILE_PATH,"w+");
		foreach($f as $line){
			//strip any whitespace chars from the end and replace with OS specific EOL
			fwrite($nf,rtrim($line) . "\r\n");
		}
		fclose($nf);//close the file
		//redirect back to showing this element
		echo "The position, <b>".$elems[0]."</b>, has been edited. <a href='position_description.php?id=$lnum'><font size='1'>View the edited position now</font></a>.<BR><BR>";
		echo "<a href='FSFPCMS.php'>Go back</a>.";
		echo "<br /><br />";//Break
	}
}
?>
</td>
<td cellpadding="10" cellspacing="10" width="25">
</tr>
</table>
</body>
</html>
Hope you can help...thanks