Jump to content

Archived

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

adamwhiles

Stripping Slashes Problem

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?

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
Thanks, worked like a charm....I just didn't understand what stripslashes() done exactly I guess

Share this post


Link to post
Share on other sites

×

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.