Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Keeping text Formatting when inputting data

Featured Replies

I'm currently using this to enter data into the table:

 

eg1 $w = mysqli_real_escape_string($dbc, trim($_POST['welcome']));

eg2 $w = mysqli_real_escape_string($dbc, str_replace("\\r\\n",'<br>',trim($_POST['welcome'])));

eg3 $w = mysqli_real_escape_string($dbc, nl2br(trim($_POST[welcome])));

 

this re displays the data after entering it (in the editing box):

$row = mysqli_fetch_array ($r, MYSQLI_NUM);

Welcome: <br /><textarea name="welcome" rows="10" cols="50" value= >' . $row[0] . '</textarea>

 

This is used to display it when referring to it in the 'news' section of the website:

$q = "SELECT news AS n, welcome AS w FROM body_text";

$r = @mysqli_query ($dbc, $q);

if ($r) {

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

echo '<h1>Welcome</h1>';

echo $row['w']; //'</td><td align="left">' . $row['n'] . '</td></tr>

 

Most of the inputs are in sentence form. I want to keep formatting if the entered data has carriage returns, I would like simple HTML if the user chose to use these (bold, italics and links etc), and I want to make it (fairly) secure.

 

eg1 is no good as it adds / and there is no HTML formatting or returns.

 

eg2 is ok but you have to manually put in the html formatting for carriage returns

 

eg3 is almost there, in the editing box it replaces the returns with <br />. If you update the text again it adds another <br /> to and returns which is no good. eg:

 

enter this:

hello

welcome to this site

 

Looks like this in the text box after updating:

hello <br />

welcome to this site

 

But if you were to make another change (add 'everyone') it looks like this:

hello everyone <br /> <br />

welcome to this site

 

Both eg 2 and 3 look correct in the final display in the website (apart from the increasing number of carriage returns).

 

 

All I want to do is keep formatting if the entered data has carriage returns, have simple HTML and not be too insecure.

 

Phew ... any help ...?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.