Jump to content

Recommended Posts

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?!

Link to comment
https://forums.phpfreaks.com/topic/116356-problem-with-formatting/
Share on other sites

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?!

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']);

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.