Questions tagged «php»

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

5
仅通过htaccess在PHP中启用错误显示
我正在在线测试一个网站。 目前,错误尚未显示(但我知道它们存在)。 我只能访问该.htaccess文件。 如何使用.htaccess文件显示所有错误? 我将以下行添加到我的.htaccess文件中: php_flag display_startup_errors on php_flag display_errors on php_flag html_errors on 现在页面显示: 内部服务器错误


7
PHP PDO返回单行
更新2: 那么这是它可以获得的最优化的吗? $DBH = new PDO( "connection string goes here" ); $STH = $DBH -> prepare( "select figure from table1" ); $STH -> execute(); $result = $STH -> fetch(); echo $result ["figure"]; $DBH = null; 更新1: 我知道我可以为sql查询增加限制,但是我也想摆脱foreach循环,这不是我所需要的。 原始问题: 我有以下脚本,由于“ foreach”部分的缘故,它是从数据库返回许多行的良好IMO。 如果我知道我将永远只从数据库中获得1行,该如何优化它。如果我知道我只会从数据库中获得1行,我不明白为什么需要foreach循环,但是我不知道如何更改代码。 $DBH = new PDO( "connection string goes here" ); …
113 php  pdo 

12
如何从PHP中的数组创建逗号分隔的列表?
我知道如何使用foreach遍历数组的项并附加逗号,但是必须取下最后的逗号总是很痛苦的。有没有简便的PHP方式? $fruit = array('apple', 'banana', 'pear', 'grape'); 最终我想要 $result = "apple, banana, pear, grape"
113 php  arrays 

3
curl_exec()总是返回false
我已经写了这段简单的代码: $ch = curl_init(); //Set options curl_setopt($ch, CURLOPT_URL, "http://www.php.net"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $website_content = curl_exec ($ch); 在我的情况$website_content当属false。谁能建议/建议出什么问题了?
113 php  curl 

14
作曲家在更新时被杀死
我遇到了一个问题,我试图为我的Laravel 4项目安装一个新软件包。但是当我跑步时php composer.phar update我得到了: Loading composer repositories with package information Updating dependencies (including require-dev) Killed 我在Internet上寻找问题,发现内存是问题,我认为我没有足够的RAM,我检查了一下一下我有411mb的空闲空间。作曲家真的需要更多RAM吗?

13
Laravel-未根据要求设置会话存储
我最近创建了一个新的Laravel项目,并遵循有关身份验证的指南。当我访问登录或注册路线时,出现以下错误: ErrorException in Request.php line 775: Session store not set on request. (View: C:\Users\Matthew\Documents\test\resources\views\auth\register.blade.php) 我还没有编辑任何核心Laravel文件,我只创建了视图并将路由添加到了route.php文件中 // Authentication routes Route::get('auth/login', ['uses' => 'Auth\AuthController@getLogin', 'as' => 'login']); Route::post('auth/login', ['uses' => 'Auth\AuthController@postLogin', 'as' => 'login']); Route::get('auth/logout', ['uses' => 'Auth\AuthController@getLogout', 'as' => 'logout']); // Registration routes Route::get('auth/register', ['uses' => 'Auth\AuthController@getRegister', 'as' => 'register']); Route::post('auth/register', …
113 php  laravel 

17
文件名的字符串清理器
我正在寻找一个将清理字符串并准备用于文件名的php函数。有人知道吗? (我会写一个,但是我担心自己会忽略一个字符!) 编辑:用于将文件保存在Windows NTFS文件系统上。
113 php  string  sanitization 

13
Laravel有一种向请求数组添加值的方法
我在使用请求参数调用store()或update()方法以在请求Eloquent函数之前向请求添加一些附加值的时候遇到了Laravel的情况,对此有什么解决方法。 function store(Request $request) { // some additional logic or checking User::create($request->all()); }
113 php  laravel 

5
PHP在关联数组前加上文字键?
是否可以在常量数组前加上文字键=>值对?我知道array_unshift()可与数字键一起使用,但我希望能与文字键一起使用的东西。 例如,我想执行以下操作: $array1 = array('fruit3'=>'apple', 'fruit4'=>'orange'); $array2 = array('fruit1'=>'cherry', 'fruit2'=>'blueberry'); // prepend magic $resulting_array = ('fruit1'=>'cherry', 'fruit2'=>'blueberry', 'fruit3'=>'apple', 'fruit4'=>'orange');

15
以编程方式访问货币汇率[关闭]
在这里很难说出要问什么。这个问题是模棱两可,含糊,不完整,过于宽泛或夸张的,不能以目前的形式合理地回答。如需帮助澄清此问题以便可以重新打开, 请访问帮助中心。 7年前关闭。 我正在建立一个在线订购系统,但我在澳大利亚,对于国际客户,我想以美元或欧元显示价格,这样他们就不必花心思从澳元转换。 有谁知道我是否可以通过PHP脚本访问的一种易于解析的格式从网上提取最新汇率? 更新:我现在编写了一个实现此目的的PHP类。您可以从我的网站上获取代码。
112 php  currency  finance 

6
通过Composer安装Symfony 2.3.x时lib-icu依赖性问题
使用Composer安装Symfony 2.2.x时没有任何问题,我一直只是在http://symfony.com/download上复制了稳定版本。 composer create-project symfony/framework-standard-edition myproject/ 2.2.1 (我在全球范围内安装了Composer) 对2.3.0-RC1感到好奇,我认为这样做会很顺利: composer create-project symfony/framework-standard-edition mynewerproject/ 2.3.0-RC1 但是由于以下错误而关机: Your requirements could not be resolved to an installable set of packages. Problem 1 - symfony/icu v1.2.0-RC1 requires lib-icu >=4.4 -> the requested linked library icu has the wrong version installed or is missing from …

9
将JSON存储在HTML属性中的最佳方法?
我需要将JSON对象放入HTML元素的属性中。 HTML不必验证。 昆汀回答:将JSON存储在data-*有效HTML5 的attribute中。 JSON对象可以是任何大小-即巨大 森·麦库(Maiku Mori)回答:HTML属性的限制可能为65536个字符。 如果JSON包含特殊字符怎么办?例如 {foo: '<"bar/>'} 昆汀回答:按照常规惯例,将JSON字符串放入属性之前进行编码。对于PHP,请使用函数。 htmlentities() 编辑-使用PHP和jQuery的示例解决方案 将JSON写入HTML属性: <?php $data = array( '1' => 'test', 'foo' => '<"bar/>' ); $json = json_encode($data); ?> <a href="#" data-json="<?php echo htmlentities($json, ENT_QUOTES, 'UTF-8'); ?>">CLICK ME</a> 使用jQuery检索JSON: $('a').click(function() { // Read the contents of the attribute (returns a …
112 javascript  php  html  json 

18
从字符串中删除非UTF8字符
我在从字符串中删除非utf8字符时出现问题,这些字符无法正确显示。像这样的字符0x97 0x61 0x6C 0x6F(十六进制表示) 删除它们的最佳方法是什么?正则表达式还是其他?
112 php  regex 

4
Laravel Schema onDelete设置为null
无法弄清楚如何在Laravel中的表上设置适当的onDelete约束。(我正在使用SqLite) $table->...->onDelete('cascade'); // works $table->...->onDelete('null || set null'); // neither of them work 我进行了3次迁移,创建了Gallery表: Schema::create('galleries', function($table) { $table->increments('id'); $table->string('name')->unique(); $table->text('path')->unique(); $table->text('description')->nullable(); $table->timestamps(); $table->engine = 'InnoDB'; }); 创建图片表: Schema::create('pictures', function($table) { $table->increments('id'); $table->text('path'); $table->string('title')->nullable(); $table->text('description')->nullable(); $table->integer('gallery_id')->unsigned(); $table->foreign('gallery_id') ->references('id')->on('galleries') ->onDelete('cascade'); $table->timestamps(); $table->engine = 'InnoDB'; }); 将图库表链接到图片: Schema::table('galleries', function($table) { // id of …

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.