%s,%1 $ s等的含义是什么?
-
-
这都是纯PHP.参见[`sprintf()`](http://www.php.net/manual/zh/function.sprintf.php).This is all plain PHP. See [`sprintf()`](http://www.php.net/manual/en/function.sprintf.php).
- 3
- 2013-09-27
- fuxia
-
该Codex可以提供WordPress特定的文档.它并非旨在教授PHP编程,并且您所有的问题都与PHP编程有关.可以在[php.net](http://php.net/)上找到PHP文档,并且可以使用Google找到许多PHP初学者教程.The Codex exists to provide WordPress-specific documentation. It is not intended to teach PHP programming, and all of your questions are about PHP programming. PHP documentation can be found at [php.net](http://php.net/), and lots of PHP beginner tutorials can by found using Google.
- 0
- 2013-09-27
- Ben Miller - Remember Monica
-
@BenMiller:请耐心等待.在toscho发表评论之前,我什至不知道问题的立场.戴夫的答案现在几乎很清楚.@BenMiller: Be patient please. Before toscho's comment, I's even unaware about the question's position. It's almost clear now with Dave's answer.
- 2
- 2013-09-27
- Mayeenul Islam
-
@MayeenulIslam,我只是想解释一下为什么您在法典中找不到这样的解释.如果遇到不耐烦的事,我感到抱歉.@MayeenulIslam, I was simply attempting to explain why you don't find such explanations in the Codex. I'm sorry if I came across as impatient.
- 0
- 2013-09-27
- Ben Miller - Remember Monica
-
1 个回答
- 投票数
-
- 2013-09-27
这实际上更像是一个一般的PHP编程问题,因此可能会被关闭.但是在那之前,让我们看看是否能帮您解决其中的一些问题.
以%符号开头的字符串为"printf格式" .例如,
%2$s
转换为"用第二个参数替换此令牌,并将其视为字符串".当您在字符串中的大括号中看到变量时,例如
"Today is {$day}"
,这与将变量没有大括号时放置在此处一样,例如"Today is $day"
.但是像这样格式化变量会使它脱颖而出,因此,很显然那里有一个变量.它还可以防止变量名称旁边的其他字符被解释为该名称的一部分.没有花括号,PHP会知道如何处理"Your robot name would be {$firstName}Number5"
吗?它会看到"$firstNameNumber5"
并查找名为$firstNameNumber5的变量,而不是简单的$firstName.我不确定您在上一个示例中要问什么.是您感到困惑的
__FILE__
吗?这是一个 PHP Magic Constant ,它已替换为文件的完整路径那段代码在里面.This is really more of a general PHP programming question and might get closed for that reason. But before that happens, let's see if I can't clear some of this up for you.
Those strings that start with % signs are in "printf format". For example,
%2$s
translates to "replace this token with the second parameter, and treat it like a string".When you see a variable in curly braces inside a string, like
"Today is {$day}"
, that's the same as putting the variable there without curly braces, like"Today is $day"
. But formatting the variable like this makes it stand out, so it's more clear there's a variable there. It also prevents other characters next to the variable name from getting interpreted as part of the name. Without curly braces, would PHP know what to do with"Your robot name would be {$firstName}Number5"
? It would see"$firstNameNumber5"
and look for a variable named $firstNameNumber5 instead of simply $firstName.I'm not sure what you're asking about in the last example. Is it the
__FILE__
you're confused by? That's a PHP Magic Constant that gets replaced with the full path to the file that bit of code is in.-
在关闭之前,只有最后一个简单的网址:`!Website ::`.为什么在那里有双冒号?Before getting closed just the last simple one: `!Website::`. Why the double colon there?
- 0
- 2013-09-27
- Mayeenul Islam
-
`::`与[面向对象编程](http://php.net/manual/en/oop5.intro.php)有关-在`Website ::getThemeOption`的情况下,调用属于类"网站"的函数"getThemeOption".The `::` has to do with [object-oriented programming](http://php.net/manual/en/oop5.intro.php) -- in the case of `Website::getThemeOption`, you're calling the function `getThemeOption` belonging to the class `Website`.
- 2
- 2013-09-27
- Pat J
-
还有:`{$ var}`可以帮助PHP区分类似`{$ complete_variable_name}`和`{$prefix} _rest_of_name`之类的东西.Also: `{$var}` helps PHP distinguish between something like `{$complete_variable_name}` and `{$prefix}_rest_of_name`, for example.
- 2
- 2013-09-27
- Pat J
-
FIY双冒号仅用于访问静态或重写的类的方法和类的属性,而常规方法则使用->例如$myObject-> someMethod();FIY double colon is used to access only static or overridden methods and properties of a class, with regular methods you use -> e.g. $myObject->someMethod();
- 0
- 2015-06-11
- ed-ta
从问答环节我遇到了一些旧事物,但是我担心自己处于一种状况,即我仍然不知道它们的含义,也不知道为什么使用它们.
%1$s
-(找到用于加载小部件ID)%2$s
-(找到用于加载小部件类的类)%s
-(找到此处)以下内容如何工作?我的意思是对代码格式的解释是什么?
!Website::getThemeOption("format_post/{$post_format}/content/hide")):
-(找到此处)if( !wp_verify_nonce( $_POST['my_noncename'] ) plugin_basename( __FILE__ ) ) return;
-(找到此处)这个问题可以继续下去,我知道.但是类似的事情在任何地方都没有清楚地解释.我不仅想要它们的含义和目的,还想要一些内在/核心的解释,以便我可以理解它们的动机以及它们的工作原理.
而且,如果在Codex中已经清楚地定义了这些内容,我希望阅读它们.如果这样的列表已经整理出来,并且希望有这样一个列表.