Jump to content

Stripping Slashes Problem


adamwhiles

Recommended Posts

I am using the stripslashes function but it isn't working correctly here what I got:

[code]
$username = $_POST['username'];
$Fname = $_POST['Fname'];
$Lname = $_POST['Lname'];
$email = $_POST['email'];
$city = $_POST['city'];
$state = $_POST['state'];

$username2 = stripslashes($username);
$Fname2 = stripslashes($Fname);
$Lname2 = stripslashes($Lname);
$email2 = stripslashes($email);
$city2 = stripslashes($city);
$state2 = stripslashes($state);
[/code]

Say $username = "f\s/d\f3/675"

Now if i echo $username2

It will output f\s/d\f3/675 without stripping anything

Also, how do I strip the forward slashes also?
Link to comment
Share on other sites

stripslashes doesnt strip all slashes out of a string, it only strips slashes that is escaping certain characters:

For example you had an apostrophe in your name, like so O'reily if you did this: O\'reily the backslash is escaping the apostrophe. Whn you use stripslashes on that name PHP will remove the slash, it'll also remove the slash if you had two backslashes. Such as \\ would be converted into \

If you want to remove slashes completely use str_replace like so:
[code]<?php

$str = "This //string\\had slashes /\ in\\ it!";

// Only strips out slashes that is escaping characters.
echo stripslashes($str) . " - with stripslashes<br />\n\n";

// use str_replace to remove \ and / characters from our string
// NOTE: two \'s was used below to stop PHP from escaping the quote mark
$str = str_replace(array("\\", "/"), '', $str);

echo $str . '- with str_replace';

?>[/code]
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.