Jump to content

Is It Possible to Allow "\" with htmlspecialchars() ?


chaseman

Recommended Posts

$asciiart_name = strip_tags(mysqli_real_escape_string($dbc, trim($_POST['asciiart_name'])));
$asciiart_category = strip_tags(mysqli_real_escape_string($dbc, trim($_POST['asciiart_category'])));
$asciiart_contribution = htmlspecialchars($_POST['asciiart_contribution']);
$asciiart_contribution = str_replace("'","''", $asciiart_contribution);

 

Above is my code, with a textarea you can post the data into the $asciiart_contribution variable, BUT you can not post anything including backslash, is there any way to allow this one character?

 

I'd still like the people to not use any html code, but at the same time I want a certain freedom of characters which includes use of backslash.

 

Thanks for all the tips.

Link to comment
Share on other sites

I'm guessing the "contribution" is the actual ASCII art itself?

$asciiart_name = strip_tags(trim($_POST["asciiart_name"]);
$asciiart_category = strip_tags(trim($_POST["asciiart_category"]));
$asciiart_contribution = $_POST["asciiart_contribution"]; // don't do anything to it

// eventually you'll put the values into the database
mysqli_query($dbc, sprintf("INSERT INTO table (name, category, contribution) VALUES ('%s', '%s', '%s')",
    mysqli_real_escape_string($dbc, $asciiart_name),
    mysqli_real_escape_string($dbc, $asciiart_category),
    mysqli_real_escape_string($dbc, $asciiart_contribution)));

// and eventually you'll get the values back out again. if you use the same variable names,
echo "Name: ", htmlentities($asciiart_name), "
\n";
echo "Category: ", htmlentities($asciiart_category), "
\n";
echo "", htmlentities($asciiart_contribution), "";

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.