如何在标点符号中使用dot而不是在PHP中附加

I'm putting a SQL query together in PHP. How do I declare a dot in punctuation?

Example code as requested:

$sql="SELECT COUNT(*) FROM Table1 WHERE LOWER(location2) REGEXP '.* .$location .*'";

See .* is a regexp and should not be interpreted by PHP as a concatenation.

This is nothing to do with PHP syntax. Your example contains a . inside a quoted string, which PHP interprets as a . inside a quoted string. Therefore nothing is wrong there.

What you're probably experiencing is MySQL treating the . as a wild-card operator in a regular expression. In regular expression syntax (whether in MySQL, PHP, Perl, wherever) . is a wild-card that matches any single character. If you want to include a literal . in your regex, you need to escape it, i.e. \..

Because you are using it inside a string inside a string, you also need to escape the \ character so that it makes it through to the regex correctly. Without testing I would say it needs escaping twice (once for PHP and once for MySQL), e.g. "'\\\\.'" in PHP becomes '\\.' in MySQL, becomes \. in the regular expression.

(Obviously, only escape the . characters that are meant to be treated literally - I would assume the .* is meant to match any character - these should not be changed.)