Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php %s在这里是什么意思?_Php_Mysql_Sql_Printf - Fatal编程技术网

Php %s在这里是什么意思?

Php %s在这里是什么意思?,php,mysql,sql,printf,Php,Mysql,Sql,Printf,%s是什么意思 $sql = "SELECT * FROM page_table WHERE page_name = '%s' LIMIT 1"; %s是在函数中使用的占位符,如。检查手册中是否有其他可能的占位符 $sql = sprintf($sql, "Test"); 这将用字符串“Test”替换%s。它还用于确保传递的参数实际符合占位符。您可以使用%d作为数字的占位符,但如果sprintf收到字符串,它会抱怨。这是一个格式化

%s
是什么意思

$sql = "SELECT * 
          FROM page_table 
         WHERE page_name = '%s' 
         LIMIT 1";

%s
是在函数中使用的占位符,如。检查手册中是否有其他可能的占位符

$sql = sprintf($sql, "Test");

这将用字符串“Test”替换
%s
。它还用于确保传递的参数实际符合占位符。您可以使用
%d
作为数字的占位符,但如果sprintf收到字符串,它会抱怨。

这是一个格式化字符串,其中
%s
是占位符。我怀疑$sql是用来将其转换为真正的查询的。例如:

$name = 'posts';
$sql = "SELECT * FROM page_table WHERE page_name = '%s' LIMIT 1";
$formattedSql = sprintf($sql, $name);
这将生成一个如下所示的查询:

SELECT * FROM page_table WHERE page_name = 'posts' LIMIT 1

当您不想随意使用引号和双引号时,这非常有用。

我想%s是的格式符号

下一行代码可能是这样的:

$sqlquery = sprintf($sql, 'mySearchString');
真正的疑问是:

从page_表中选择*,其中page_名称='mySearchString'限制1


我们使用%s作为字符代码,因为ASCII 65是“A”,所以直到91“Z”,为了更好地理解,您可以在使用printf的for循环打印结果中使用从65到91的for循环

用于($i=65;$i)
我会给你这样的东西

$sql =select * from page_table where page_name='page' LIMIT 1";

打得好,我一读就会把它和“%s”之类的
混淆了。
$sql =select * from page_table where page_name='page' LIMIT 1";