Jump to content

Advanced Text Input.


njdubois

Recommended Posts

You have seen what I am talking about, they are all over the web.  This text box I'm typing in now is a fine example!

 

I need a textbox that, well, I need a text input method that strips all the important/security related characters from a string while retaining CRLF's and text formatting.  To be saved to a mysql database.

 

But when I am pulling that data to be displayed somewhere, I want to place said characters back into the string.

 

What direction should I look to find a solution?

 

Thanks

Nick

Link to comment
Share on other sites

htmlentities looks to be what I was searching for, thanks!

 

As far as security characters, I meant characters that are special to mysql.  For example single and double quotes.  Which if I don't manage right, could lead to sql attacks.

 

Thanks again for the help ladies and gents!

 

Nick

Link to comment
Share on other sites

From the replies here I came up with :

<?php

if(isset($_POST['ok'])) {
$in_str = $_POST['text_in'];

$to_data = addslashes($in_str);
$to_data = stripcslashes(ereg_replace("(\r\n|\n|\r)", "<br />", $to_data));

$display_output = stripcslashes(ereg_replace("(\r\n|\n|\r)", "<br />", $to_data));

$edit_output = stripcslashes(ereg_replace("(<br />)", "\r\n", $to_data));

echo 'Formated For Database : <br />';
echo '<textarea cols="100" rows="5">'.$to_data.'</textarea>';
echo '<br /><br />';

echo 'Displayed from Database : <br />' . $display_output;
echo '<br /><br />';
}




echo 'New, or for Edit from database : <br />';

echo '<form name="text_input" method="post" action="text_stuff.php">';
echo '<textarea id="text_in" name="text_in" cols="100" rows="10">'.$edit_output.'</textarea>';
echo '<input type="submit" id="ok" name="ok" value="Ok" />';
echo '</form>';

?>

 

Does the job perfectly.

 

Many Thanks

Nick

Link to comment
Share on other sites

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.