Questions tagged «php»

PHP是一种广泛使用的高级动态,面向对象和解释性脚本语言,主要用于服务器端Web开发。用于有关PHP语言的问题。

8
PHP中的动态类方法调用
有没有一种方法可以在PHP的同一类中动态调用方法?我没有正确的语法,但我正在寻找类似的方法: $this->{$methodName}($arg1, $arg2, $arg3);
87 php 



5
PHP-在类中定义常量
我如何在类内部定义一个常量,并使其使其仅在类上下文中被调用时才可见? ....就像是 Foo::app()->MYCONSTANT; (如果被称为喜欢MYCONSTANT被忽略)
87 php  class  constants 

9
将1天添加到DATETIME格式值
在某些情况下,我想在DATETIME格式化变量的值上加上1天: $start_date = date('Y-m-d H:i:s', strtotime("{$_GET['start_hours']}:{$_GET['start_minutes']} {$_GET['start_ampm']}")); 做这个的最好方式是什么?
87 php  mysql  date  datetime 

11
Laravel中间件将变量返回给控制器
我正在对用户进行权限检查,以确定他们是否可以查看页面。这涉及首先通过一些中间件传递请求。 我遇到的问题是在将数据返回到视图本身之前,我正在中间件和控制器中复制相同的数据库查询。 这是设置示例; --routes.php Route::get('pages/{id}', [ 'as' => 'pages', 'middleware' => 'pageUser' 'uses' => 'PagesController@view' ]); -PageUserMiddleware.php(PageUserMiddleware类) public function handle($request, Closure $next) { //get the page $pageId = $request->route('id'); //find the page with users $page = Page::with('users')->where('id', $pageId)->first(); //check if the logged in user exists for the page if(!$page->users()->wherePivot('user_id', Auth::user()->id)->exists()) …


5
带有file_get_contents的HTTP请求,获取响应代码
我试图file_get_contents一起使用stream_context_create以发出POST请求。到目前为止,我的代码: $options = array('http' => array( 'method' => 'POST', 'content' => $data, 'header' => "Content-Type: text/plain\r\n" . "Content-Length: " . strlen($data) . "\r\n" )); $context = stream_context_create($options); $response = file_get_contents($url, false, $context); 它工作正常,但是,当发生HTTP错误时,它会发出警告: file_get_contents(...): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request 并返回false。有没有办法: 禁止显示警告(如果发生故障,我打算抛出自己的异常) 从流中获取错误信息(至少是响应代码)
87 php  file  http  stream 


20
如何检查是否存在多个数组键
我有各种各样的数组,要么包含 story & message 要不就 story 如何检查数组是否同时包含故事和消息? array_key_exists()只在数组中查找该键。 有没有办法做到这一点?
87 php  key 

5
将项目添加到关联数组
//go through each question foreach($file_data as $value) { //separate the string by pipes and place in variables list($category, $question) = explode('|', $value); //place in assoc array $data = array($category => $question); print_r($data); } 这无法正常工作,因为它替换了数据的值。我如何让它在每个循环中添加一个关联值?$file_data是具有动态大小的数据数组。
87 php 

15
使用PHP获取目录中所有文件的名称
出于某种原因,我使用以下代码将文件名始终保持为“ 1”: if (is_dir($log_directory)) { if ($handle = opendir($log_directory)) { while($file = readdir($handle) !== FALSE) { $results_array[] = $file; } closedir($handle); } } 当我在$ results_array中回显每个元素时,我得到了一堆“ 1”,而不是文件名。如何获得文件名?

10
验证ImageMagick安装
我的网络托管人员说ImageMagic已预安装在服务器上。我在phpinfo()的输出中快速搜索了“ ImageMagick”,却一无所获。我无法在服务器中使用SSH,因此PHP中是否可以验证安装?
87 php  imagemagick 

13
$ date + 1年?
我正在尝试从指定的日期开始算起一年的日期。 我的代码如下所示: $futureDate=date('Y-m-d', strtotime('+one year', $startDate)); 返回错误的日期。有什么想法吗?
87 php  strtotime 

6
有没有办法检测Laravel是否存在数据库表
我希望能够使用创建表 Schema::create('mytable',function($table) { $table->increments('id'); $table->string('title'); }); 但在此之前,我想检查表是否已经存在,也许像 Schema::exists('mytable'); 但是,以上功能不存在。我还能使用什么?
87 php  laravel 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.