19

What does the \x1a character mean and why does mysql_real_escape_string escape it?

From the documentation:

mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a.

A ASCII Characters reference describes it as Substitute character, but this doesn't say much.

Emanuil Rusev
  • 34,563
  • 55
  • 137
  • 201

5 Answers5

14

It's a Unicode escape sequence, in hexadecimal (base 16). \x1a is the "substitute" character.

See also: https://en.wikipedia.org/wiki/Substitute_character


Why does mysql_real_escape_string escape it?

According to the documentation,

Strictly speaking, MySQL requires only that backslash and the quote character used to quote the string in the query be escaped. mysql_real_escape_string() quotes the other characters to make them easier to read in log files.

Mr.Z
  • 542
  • 2
  • 5
  • 18
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
14

\x1A is the CTRL+Z control character. It is also EOF marker.

Freddy Mcloughlan
  • 4,129
  • 1
  • 13
  • 29
Ziumin
  • 4,800
  • 1
  • 27
  • 34
4

\x1a is a SUB control character, used to mark end of a file (EOF).

keeri
  • 809
  • 2
  • 13
  • 19
2

It is a hexadecimal escape sequence for the SUB character.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0

This is is because of an empty line et the eof file the program try to read the values in the empty line and read \x1a

Nelu
  • 151
  • 1
  • 6