wizr Posted September 9, 2010 Share Posted September 9, 2010 I recently made a flatfile cms (+ edit in place). Here's an example of how it shows the <br>'s when hitting enter. The password is demo. Now when you click inside (in any text field - there are 4), when hitting enter it makes a new line without showing a <br> tag. Clicking outside and inside the textarea, it will show all the line breaks you've made. My question is how to hide the <br> tag. What I've searched, found and tried the following: $content=nl2br($content); and $content = str_replace("<br>", "\n", $content); Neither worked. Also when using this code $file1 = include '/ccms/files/edit.txt'; echo $file1; // This outputs the file. to show the content on another page, it adds a number 1 to every textarea I have on the original page. You can preview the number 1 error here. Quote Link to comment Share on other sites More sharing options...
schilly Posted September 9, 2010 Share Posted September 9, 2010 str_replace("<br>", "\n", $content); should work. Are you writing to the file with the <br> in it? Quote Link to comment Share on other sites More sharing options...
wizr Posted September 9, 2010 Author Share Posted September 9, 2010 str_replace("<br>", "\n", $content); Also doesn't work, it hides the <br>'s, but doesn't actually make one, its like doing a <br> and not going into the next line. (that line sort of disables <br>'s not only hiding them.) Quote Link to comment Share on other sites More sharing options...
wizr Posted September 9, 2010 Author Share Posted September 9, 2010 Also when using this code $file1 = include '/ccms/files/edit.txt'; echo $file1; // This outputs the file. to show the content on another page, it adds a number 1 to every textarea I have on the original page. You can preview the number 1 error here. I found a fix to this, instead of $file1 = include '/ccms/files/edit.txt'; echo $file1; // This outputs the file. using $file1 = include '/ccms/files/edit.txt'; $file1 = substr($file1, 0, -1); echo $file1; removes the "number 1" that becomes visible for no good reason at each textarea. Or even better, using this below works without and errors. $file1 = file_get_contents('/ccms/files/edit.txt'); echo $file1; But still the hiding of <br> remains a mystery. What we've done till now is: str_replace("<br>", "\n", $content); - it does hide the <br> tag, but it makes it inactive. Quote Link to comment Share on other sites More sharing options...
schilly Posted September 9, 2010 Share Posted September 9, 2010 Yes if you want to read a file into a variable use file_get_contents(). include probably returns a bool so that's why you were getting a 1 as it successfully included the file. it is not meant for reading it into a variable. For removing the <BR> how does it make it in active? You should be not be writing the BRs to your flat file. Just when you display the data use nl2br() and it should work fine. Write the textarea data to the flatfile which contains "\n"s then when you display just use nl2br. Quote Link to comment Share on other sites More sharing options...
wizr Posted September 10, 2010 Author Share Posted September 10, 2010 If I use the code you gave me, it hides the <br>'s successfully, but when I enter a new line in the textarea it just doesn't happen. Like it removes <br> completely, not just hides it. I'm trying different variations, do you think the js library could be the problem, instead of php? Quote Link to comment Share on other sites More sharing options...
schilly Posted September 10, 2010 Share Posted September 10, 2010 How does the application work? The process from editing the textarea to it saving and outputting the info. Quote Link to comment Share on other sites More sharing options...
wizr Posted September 10, 2010 Author Share Posted September 10, 2010 It's a really simple thing, in a few steps: It makes a textarea that is writable to a .txt file. I display this text area with: <div id="change"><span id="a1" class="editText"><? echo $textInfile; ?></span></div> . This goes trough: <? $thefile = "files/edit.txt"; $textInfile = file_get_contents($thefile); ?> This saves the file to edit.txt The main config has these: $fieldname = htmlspecialchars($_GET['fieldname']); $content = stripslashes(strip_tags($_GET['content'],"<p><img><i></i></p><h1></h1><h2></h2></a><li></li><a><strong><em><strike><b>")); $content = trim($content); $content=nl2br($content); User enters content into the text area and it writes it directly to the txt file once the user clicks out of the area. So far the most efficient thing that worked (or not) is : str_replace("<br>", "\n", $content); This would be perfect if it didn't disable <br>'s completely. Also another thing, when you click on the text area on http://krneky.com/ccms (password demo) the text area shows normal <br> tags, while the ones saved in http://krneky.com/ccms/files/edit3.txt (the text files), shows <br />. I have no idea what else is there to try. Edit: I'm also using - http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js - http://krneky.com/ccms/js/editInplace.js - http://krneky.com/ccms/js/wkrte.js - http://krneky.com/ccms/js/jquery-1.3.2.min.js Do you think any one of these may be causing problems? Quote Link to comment Share on other sites More sharing options...
wizr Posted September 13, 2010 Author Share Posted September 13, 2010 All fixed and ready for download, the problem was fixed by changing function editBox(actual) { if(!changing){ width = widthEl(actual.id) + 20; height =heightEl(actual.id) + 2; actual.innerHTML = "<textarea…" changing = true; } actual.firstChild.focus(); } to function editBox(actual) { if(!changing){ width = widthEl(actual.id) + 20; height =heightEl(actual.id) + 2; str = actual.innerHTML; actual.innerHTML = str.replace(/<br>/gi, ""); actual.innerHTML = "<textarea…" changing = true; } actual.firstChild.focus(); } The WonderCMS is now available for download: WonderCMS Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.