[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: addslashes

Daniel Martin

6/25/2007 7:14:00 PM

"Fred Phillips" <fophillips1990@gmail.com> writes:

> Is there a built-in function in Ruby similar to PHP's addslashes() function?
> MySQL keeps breaking...

Well, this probably indicates that you're doing sql by dynamically
building statements, which is generally a frowned-upon practice in
favor of using prepared statements with ? placeholders. However, if
you're absolutely determined to do this:

def addslashes(str)
str.gsub(/['"\\\x0]/,'\\\\\0')
end

def stripslashes(str)
str.gsub(/\\(.)/,'\1')
end

--
s=%q( Daniel Martin -- martin@snowplow.org
puts "s=%q(#{s})",s.to_a.last )
puts "s=%q(#{s})",s.to_a.last