Tag: PHP的

PHP类方法中的下划线是什么?

在查看各种PHP库时,我注意到很多人select用一个下划线前缀一些类方法,例如 public function _foo() …代替… public function foo() 我意识到,最终这归结为个人喜好,但我想知道是否有人对这种习惯从何而来有所了解。 我的想法是,它可能是从PHP 4inheritance,在类方法可能被标记为受保护或私有之前,作为一种暗示“不要从课堂外调用此方法”的方式。 然而,我也想到,它可能起源于我不熟悉的某个地方(一种语言),或者可能有充分的理由使我从中受益。 任何想法,见解和/或意见将不胜感激。

将值复制到PHP中的键

我有这个数组: $a = array('b', 'c', 'd'); 有一个简单的方法来将数组转换为以下? $a = array('b' => 'b', 'c' => 'c', 'd' => 'd');

PHP计算年龄

我正在寻找一种方法来计算一个人的年龄,给出他们的生日格式dd / mm / yyyy。 我正在使用以下几个月工作正常的函数,直到某种毛刺导致的while循环永远不会结束,并磨碎整个网站停下来。 由于每天几乎有数十万个DOB经历这个function,因此很难确定是什么原因造成的。 有没有人有更可靠的方法来计算年龄? //replace / with – so strtotime works $dob = strtotime(str_replace("/","-",$birthdayDate)); $tdate = time(); $age = 0; while( $tdate > $dob = strtotime('+1 year', $dob)) { ++$age; } return $age; 编辑:这个function似乎工作确定一些时间,但返回“40”为14/09/1986 DOB return floor((time() – strtotime($birthdayDate))/31556926);

跟踪数据库模式更改的机制

跟踪和/或自动化数据库模式更改的最佳方法是什么? 我们的团队使用Subversion进行版本控制,并且我们已经能够以这种方式自动化我们的一些任务(将构build到临时服务器,将testing代码部署到生产服务器),但是我们仍然在手动进行数据库更新。 我希望find或创build一个解决scheme,使我们能够跨不同环境的服务器高效地工作,同时继续使用Subversion作为后端,通过它将代码和数据库更新推送到各种服务器。 许多stream行的软件包包括检测数据库版本并应用必要更改的自动更新脚本。 这是甚至在更大规模(跨多个项目,有时多个环境和语言)上做到这一点的最好方法吗? 如果是的话,是否有任何现有的代码简化了stream程,或者最好是推出我们自己的解决scheme? 有没有人实现过类似的东西,并将其集成到Subversion post-commit挂钩中,或者这是一个坏主意? 虽然支持多种平台的解决scheme是可取的,但我们绝对需要支持Linux / Apache / MySQL / PHP堆栈,因为大部分工作都在该平台上。

PHP sprintf转义%

我想要以下输出: 将从您的充值帐户中扣除27.59欧元的50%。 当我做这样的事情: $variablesArray[0] = '€'; $variablesArray[1] = 27.59; $stringWithVariables = 'About to deduct 50% of %s %s from your Top-Up account.'; echo vsprintf($stringWithVariables, $variablesArray); 但它给了我这个错误vsprintf() [function.vsprintf]: Too few arguments in …因为它认为%在50%也replace。 我如何逃避它?

消毒string,使他们的URL和文件名安全?

我试图想出一个function,对某些string进行消毒,以便它们可以安全地在URL中使用(比如post-slug),并且可以安全地用作文件名。 例如,当某人上传文件时,我想确保从名称中删除所有危险字符。 到目前为止,我已经想出了以下function,我希望能解决这个问题,并允许外国的UTF-8数据。 /** * Convert a string to the file/URL safe "slug" form * * @param string $string the string to clean * @param bool $is_filename TRUE will allow additional filename characters * @return string */ function sanitize($string = '', $is_filename = FALSE) { // Replace all weird characters with dashes $string = preg_replace('/[^\w\-'. […]

当从上游读取响应报头时,上游发送太大的报头

我遇到了这样的错误: 2014/05/24 11:49:06 [error] 8376#0: *54031 upstream sent too big header while reading response header from upstream, client: 107.21.193.210, server: aamjanata.com, request: "GET /the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https://aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20https:/aamjanata.com/the-brainwash-chronicles-sponsored-by-gujarat-government/,%20ht 总是这样。 一个url一遍又一遍地用逗号分隔。 无法弄清楚是什么原因造成的。 任何人有一个想法? 更新:另一个错误: http request count is zero while sending response to client 这是configuration。 还有其他不相干的东西,但这部分是增加/编辑的 fastcgi_cache_path /var/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_ignore_headers Cache-Control […]

PHP:从数组中删除一个元素

有一种简单的方法来从PHP数组中删除元素,例如foreach ($array)不再包含该元素? 我认为把它设置为null将做到这一点,但显然不是。

列出一个目录中的所有文件PHP

使用PHP将所有文件列在一个目录中的最好方法是什么? 有一个$ _SERVER函数来做到这一点? 我想列出用户名/目录中的所有文件,并用链接遍历结果,以便我可以单击文件名的超链接来到那里。 谢谢!

防止直接访问php包含文件

我有一个PHP文件,我将作为一个包括使用。 因此,我想抛出一个错误,而不是执行它时,直接通过inputURL而不是被包括在内。 基本上我需要在php文件中进行如下检查: if ( $REQUEST_URL == $URL_OF_CURRENT_PAGE ) die ("Direct access not premitted"); 是否有捷径可寻?