25 03, 2009

addslashes

By | 2009-03-27T14:28:04+00:00 March 25th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on addslashes

Addslashes takes a string as an argument, and returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote [ ‘ ], double quote [ ” ], backslash [ \ ] and NULL (the NULL byte).

PHP

echo addslashes("Here's some money for your lunch");
// => Here\'s some money for your lunch

Ruby

puts "Here's some money for your lunch".gsub(/['"\\\x0]/,'\\\\\0');
# => Here\'s some money for your lunch

As you can see above, the easiest way to emulate the PHP function addslashes() in Ruby is to use regular expressions.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.