[Solved] Stripslashes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Moocat
Forum Contributor
Posts: 143
Joined: Wed Oct 12, 2005 9:28 am
Location: USA

[Solved] Stripslashes

Post by Moocat »

Stripslashes isn't working for me for some reason, could it be a wrong setting? (magic quotes are on)

Code: Select all

Tag strip
<br><br>

<?php
if(isset($_POST['test'])) {
	$text = $_POST['test'];
	//$text = strip_tags($text);
	echo stripslashes($text);
}
?> 

<form action="new3.php" method="post">

<input type="text" name="test">

<input type="submit">

</form>
Last edited by Moocat on Thu Feb 09, 2006 12:03 pm, edited 1 time in total.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

What do you mean by isn't working? There is nothing in your post/example that indicates it isn't working.

What is the user input? What is the output both with and without stripslashes?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Echo $text before calling stripslashes and see what you get.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Moocat
Forum Contributor
Posts: 143
Joined: Wed Oct 12, 2005 9:28 am
Location: USA

Post by Moocat »

It isn't working as in:

enterted input: test / test

ouput: test / test

EDIT: I found out that it only strips \ slashes not / slashes. And even then it doesn't seem to be working right.

entered input: test \ test

output (before strip): test \\ test
output (after strip): test \ test

Weird, any reason why this happens? By the way, I placed this in secruity because I'm looking for an all around good input text parser. Figured it's more specifically related to security although I understand I did not initially state so.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

/ is not an escape character, \ is and escaping character, used both by PHP and MySQL (amongst others).
User avatar
Moocat
Forum Contributor
Posts: 143
Joined: Wed Oct 12, 2005 9:28 am
Location: USA

Post by Moocat »

Jenk wrote:/ is not an escape character, \ is and escaping character, used both by PHP and MySQL (amongst others).
Thanks, problem solved :) I guess I should've explained my reasons for asking more thoroughly in the first place.
Post Reply