PHP "stripclashes" equivalent in Ruby/Rails?

I’m porting some code from PHP into Rails; is there an equivalent of the
PHP “stripcslashes” function in Ruby/Rails?

http://us.php.net/stripcslashes

Ben K. wrote:

I’m porting some code from PHP into Rails; is there an equivalent of the
PHP “stripcslashes” function in Ruby/Rails?

http://us.php.net/stripcslashes

Well, It shouldn’t be hard :slight_smile:

Does the function just strip the slashes as below?

Example
'nice\nguy'

Result
‘nice
guy’

Hi, Jamal. I ended up using the delete function and you are right, it
wasn’t hard :slight_smile: I wasn’t sure what the PHP function did exactly since
I’m not a PHP developer but I ended up doing something like this and I
believe it duplicates the PHP functionality:

data.delete(’\r’).delete(’\n’).delete("\")

Jamal S. wrote:

Well, It shouldn’t be hard :slight_smile:

Does the function just strip the slashes as below?

Example
‘nice\nguy’

Result
‘nice
guy’

Ben K. wrote:

Hi, Jamal. I ended up using the delete function and you are right, it
wasn’t hard :slight_smile: I wasn’t sure what the PHP function did exactly since
I’m not a PHP developer but I ended up doing something like this and I
believe it duplicates the PHP functionality:

data.delete(’\r’).delete(’\n’).delete("\")

Jamal S. wrote:

Well, It shouldn’t be hard :slight_smile:

Does the function just strip the slashes as below?

Example
‘nice\nguy’

Result
‘nice
guy’

If you just want to remove them, then you can use the delete function as
you did.

But you must understand that

\n is like

\ is like
\t is like TABKEY

So you might want to think about that :slight_smile:

Hi, Jamal. I had to remove the first 2 delete calls since it was
deleting all my “r” and “n” characters (e.g. notes became otes). I
wasn’t sure how I could delete carriage-returns and new-lines instead of
r and n characters.? For example, I tried both, \r and \r with delete.

Anyway, for now, I think just removing back-slashes will do the trick
based on this description of the PHP function (and what I think, is our
requirement :slight_smile:

http://us.php.net/stripcslashes

Thanks for all your help!

Jamal S. wrote:

If you just want to remove them, then you can use the delete function as
you did.

But you must understand that

\n is like

\ is like
\t is like TABKEY

So you might want to think about that :slight_smile:

On Jul 21, 2007, at 11:51 , Ben K. wrote:

I’m porting some code from PHP into Rails; is there an equivalent
of the
PHP “stripcslashes” function in Ruby/Rails?

What are you trying to accomplish with stripslashes? (I.e., what are
you trying to use stripslashes for?) There may be a better way to
accomplish what you’re trying to do. The reason I ask is that I’ve
often seen stripslashes used when interpolating into an SQL query
string, which is a great way to set yourself up for SQL injection. A
safe way to do the same thing is using bind variables. For (a simple,
better-accomplished-via-a-straight-up-find) example:

sql = “SELECT * FROM foo WHERE foo_id = :foo_id”
id = 3
Foo.find_by_sql([sql, {:foo_id => id}])

If you’re not interpolating into an SQL query string please ignore
the above. I still think there’s a better way to do whatever you’re
trying to accomplish with stripslashes. What are you trying to do?

Hoping to help,

Michael G.
grzm seespotcode net

Michael G. wrote:

PHP “stripcslashes” function in Ruby/Rails?

What are you trying to accomplish with stripslashes? (I.e., what are

Note he said “stripcslashes” not “stripslashes”. Different function.

Eric

On Jul 21, 2007, at 12:55 , Eric A. wrote:

Michael G. wrote:

PHP “stripcslashes” function in Ruby/Rails?

What are you trying to accomplish with stripslashes? (I.e., what are

Note he said “stripcslashes” not “stripslashes”. Different function.

Good eye :slight_smile: I missed that. Thanks, Eric. Request for application
still stands, however.

Michael G.
grzm seespotcode net