Image

PHP - String function - String function

String function

If you were a cat, string functions would be the cat's meow, all puns intended. Besides being a large part of your PHP code, they provide much of the functionality to identify and alter your data into other formats, such as arrays

addslashes($string)

Adds backslashes (escape string) to items within $string to make it safe for database queries. Effects single quotes ( ' ), double quotes ( " ), backslashes ( \ ), and the NUL byte.

Example:
$string = ' Tom said, "Marcus is mad!"';
echo $string;
$string = addslashes($string);
echo $string;
Tom said, "Marcus is mad!" Tom said, \"Marcus is mad!\"
See Also:
get_magic_quotes_gpc – Server setting for automatically applying
addslashes to GET/POST/COOKIE data
stripslashes() – Remove the backslashes created by addslashes()

stripslashes($string)
Removes backslashes (escape string) from items within $string added
throughaddslashes() or magic_quotes_gpc.
Example:
$string = ' Tom said, "Marcus is mad!"';
$string = addslashes($string);
echo $string;
$string = stripslashes($string);
echo $string;
Tom said, \"Marcus is mad!\" Tom said, "Marcus is mad!"

Math's Function

  • abs — Absolute value
  • bindec — Binary to decimal
  • decbin — Decimal to binary
  • dechex — Decimal to hexadecimal
  • decoct — Decimal to octal
  • hexdec — Hexadecimal to decimal
  • log — Natural logarithm
  • max — Find highest value
  • min — Find lowest value
  • sqrt — Square root