geoldr Posted July 24, 2008 Share Posted July 24, 2008 Hello all, so I have a question. I have programmed a application which let's registered users on my website store create text documents online. Everything is finished and works great. When you make a new document it displays its title and its linked to the page where if you click you can read the actual document. Just like a forum post. Anyways, here's the problem. I am using <pre> tags to save my formatting. Some users like to put spaces, and I myself like to make multiple paragraph breaks. Well, with the <pre> tag, if a user posts one long sentence, the sentence comes off my page!! If I don't use the <pre> tag, then everything looks good, but there is no formatting. Of course, I know I can replace the ' ' with an "nbsp" and a line break with a <br> tag, but heres why I don't want to do that. If a user wants to edit a page, it takes them back to the same dialog and inputs their information into the text fields. If my program were to replace everything, their document would have all sorts of HTML code in it! And I don't want that. So my question is, how do I get passed this? This is very important, and I can't seem to find a solution. How do all forum pages do it? And if you go to the forum post edit page, there is no HTML code, so theres obviously a way to do it, but how?! Quote Link to comment https://forums.phpfreaks.com/topic/116356-problem-with-formatting/ Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 This is rather a CSS problem then PHP. Unless you can show us the code you use to display the text document. Quote Link to comment https://forums.phpfreaks.com/topic/116356-problem-with-formatting/#findComment-598284 Share on other sites More sharing options...
geoldr Posted July 24, 2008 Author Share Posted July 24, 2008 Well, I posted there too, and heres the message again, since the tags actually got recorded. Hello all, so I have a question. I have programmed a application which let's registered users on my website store create text documents online. Everything is finished and works great. When you make a new document it displays its title and its linked to the page where if you click you can read the actual document. Just like a forum post. Anyways, here's the problem. I am using < pre > tags to save my formatting. Some users like to put spaces, and I myself like to make multiple paragraph breaks. Well, with the < pre > tag, if a user posts one long sentence, the sentence comes off my page!! If I don't use the < pre > tag, then everything looks good, but there is no formatting. Of course, I know I can replace the ' ' with an "nbsp" and a line break with a < br > tag, but heres why I don't want to do that. If a user wants to edit a page, it takes them back to the same dialog and inputs their information into the text fields. If my program were to replace everything, their document would have all sorts of HTML code in it! And I don't want that. So my question is, how do I get passed this? This is very important, and I can't seem to find a solution. How do all forum pages do it? And if you go to the forum post edit page, there is no HTML code, so theres obviously a way to do it, but how?! Quote Link to comment https://forums.phpfreaks.com/topic/116356-problem-with-formatting/#findComment-598304 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 so its displaying the HTML tags? instead of actually using them? Quote Link to comment https://forums.phpfreaks.com/topic/116356-problem-with-formatting/#findComment-598307 Share on other sites More sharing options...
unkwntech Posted July 24, 2008 Share Posted July 24, 2008 The same way you insert a < br /> for line breaks you need to reverse this. Example: On Insert: <?php pre_replace('/(?:\r|\n|\r\n)/', '<br />', $_POST['content']); This is a rough way that you might be turning \r and \n into < br /> Just revers this process for the edit: <?php pre_replace('<br />', '/(?:\r|\n|\r\n)/', $_POST['content']); Quote Link to comment https://forums.phpfreaks.com/topic/116356-problem-with-formatting/#findComment-598315 Share on other sites More sharing options...
wildteen88 Posted July 24, 2008 Share Posted July 24, 2008 Well, I posted there too, and heres the message again, since the tags actually got recorded. Hello all, so I have a question. I have programmed a application which let's registered users on my website store create text documents online. Everything is finished and works great. When you make a new document it displays its title and its linked to the page where if you click you can read the actual document. Just like a forum post. Anyways, here's the problem. I am using < pre > tags to save my formatting. Some users like to put spaces, and I myself like to make multiple paragraph breaks. Well, with the < pre > tag, if a user posts one long sentence, the sentence comes off my page!! If I don't use the < pre > tag, then everything looks good, but there is no formatting. Of course, I know I can replace the ' ' with an "nbsp" and a line break with a < br > tag, but heres why I don't want to do that. If a user wants to edit a page, it takes them back to the same dialog and inputs their information into the text fields. If my program were to replace everything, their document would have all sorts of HTML code in it! And I don't want that. So my question is, how do I get passed this? This is very important, and I can't seem to find a solution. How do all forum pages do it? And if you go to the forum post edit page, there is no HTML code, so theres obviously a way to do it, but how?! Do not convert the spaces or newlines when the data is added to the database. Only do this when you display the data on the webpage. This is the most easiest solution for you to manage and allows your users to edit the text with out having to deal with HTML. Quote Link to comment https://forums.phpfreaks.com/topic/116356-problem-with-formatting/#findComment-598831 Share on other sites More sharing options...
geoldr Posted July 24, 2008 Author Share Posted July 24, 2008 I have tried as you guys have said, using the str_replace function, everything works, but the output still looks just the same as the < pre > tags.. Quote Link to comment https://forums.phpfreaks.com/topic/116356-problem-with-formatting/#findComment-598970 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.