Jump to content

Recommended Posts

I'm having a difficult time with this code. I have a form with a text box that the user can enter in anything they want. They use special characters and I'm not adept at handling that.

this is the code that gets me in trouble:

$specialR=$_POST['specialRequests'];
$_SESSION['specialRequests']=$specialR;
$_SESSION['specialRequests'] = str_replace("&", "&", $_SESSION['specialRequests']);
$_SESSION['specialRequests'] = str_replace("<", "-", $_SESSION['specialRequests']);
$_SESSION['specialRequests'] = str_replace(">", "-", $_SESSION['specialRequests']);
$_SESSION['specialRequests'] = str_replace("'", "´", $_SESSION['specialRequests']);
$_SESSION['specialRequests'] = str_replace("/", "", $_SESSION['specialRequests']);

If I submit "Don't Print" in the form field specialRequests and then echo back $_SESSION['specialRequests] I get "Don\'t Print" when I just want to see "Don't Print". Do you know a way around this?

 

I tried putting in str_replace for $_SESSION['specialRequests'] = str_replace("\", "", $_SESSION['specialRequests']); but that doesn't work because of the special character \. Argh.

Link to comment
https://forums.phpfreaks.com/topic/142519-solved-str_replace/
Share on other sites

I've been a bad boy and magic quotes are enabled

 

what now?

 

I highly recommend disabling magic quotes (Example 1 in link). If you can't, disable them at runtime (Example 2 in link)

http://us2.php.net/manual/en/security.magicquotes.disabling.php

Link to comment
https://forums.phpfreaks.com/topic/142519-solved-str_replace/#findComment-746850
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.