Jump to content

[SOLVED] str_replace "\"


simon551

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

Archived

This topic is now archived and is closed to further replies.

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