Questions tagged «php»

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


6
Laravel,sync()-如何同步数组并传递其他数据透视字段?
Laravel官方文档具有以下sync()功能: $user->roles()->sync( array( 1, 2, 3 ) ); 您还可以将其他数据透视表值与给定的ID相关联: $user->roles()->sync( array( 1 => array( 'expires' => true ) ) ); 在后一个示例中,仅添加了一个枢轴行。我不明白的是,如果要同步的行多,如何关联其他数据透视表记录? 提前致谢。
77 php  laravel  pivot  eloquent  sync 

7
Symfony2和date_default_timezone_get()-依靠系统的时区设置并不安全
我有一个Symfony2项目。我今天将php更新到5.5.7,从那时起,我开始 Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected …
77 php  symfony  timezone 

16
PHP函数返回数组
我需要从一个函数返回多个值,因此我已将它们添加到数组中并返回了该数组。 <? function data(){ $a = "abc"; $b = "def"; $c = "ghi"; return array($a, $b, $c); } ?> 我怎么能接受的价值观$a,$b,$c通过调用上述功能?
77 php  arrays  function 

12
无法通过PHPMailer使用Gmail SMTP服务器发送电子邮件,出现错误:在端口587上提交邮件需要SMTP AUTH。如何解决?
我想通过PHP Mailer使用Gmail SMTP服务器发送电子邮件。 这是我的代码 <?php require_once('class.phpmailer.php'); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->CharSet="UTF-8"; $mail->SMTPSecure = 'tls'; $mail->Host = 'smtp.gmail.com'; $mail->Port = 587; $mail->Username = 'MyUsername@gmail.com'; $mail->Password = 'valid password'; $mail->SMTPAuth = true; $mail->From = 'MyUsername@gmail.com'; $mail->FromName = 'Mohammad Masoudian'; $mail->AddAddress('anotherValidGmail@gmail.com'); $mail->AddReplyTo('phoenixd110@gmail.com', 'Information'); $mail->IsHTML(true); $mail->Subject = "PHPMailer Test Subject via Sendmail, basic"; …
77 php  smtp  gmail  phpmailer 

4
PSR-0代表什么?[关闭]
关闭。这个问题是题外话。它当前不接受答案。 想改善这个问题吗? 更新问题,使其成为Stack Overflow的主题。 7年前关闭。 改善这个问题 我知道什么是PSR-0,以及如何,为什么,在哪里使用它。 我GOOGLE了这个四处张望计算器相关的职位,但未能发现任何东西。即使在其官方页面上也没有这样的定义。 因此,问题是,PSR-0到底代表什么?
77 php 

2
FLOW3动作参数和对象数组
FLOW3提供了一种方便的方法,可以通过URL中的ID传递实体,并在controller动作的参数中自动实例化它们: class PostController extends \TYPO3\FLOW3\MVC\Controller\ActionController { public function editAction(Post $post) { ... } } 但是,如果您有一个复选框,每个复选框代表一个特定的对象,该用例如何?也可以自动实例化它们: <input type="checkbox" name="tags[]" value="1" /> <input type="checkbox" name="tags[]" value="2" /> ... 有没有办法告诉FLOW3将实例自动实例$tags化为Tag对象数组?就像是: public function setTagsAction(Post $post, /** @var Model\Tag */ array $tags) { $post->setTags($tags); }

12
拒绝直接访问除index.php之外的所有.php文件
我想拒绝直接访问.php除以下文件之外的所有文件:index.php 只能.php通过php访问其他文件include。 如果可能的话,我希望所有文件都在同一文件夹中。 更新: 一般规则会很好,所以我不需要浏览所有文件。风险是我忘记了文件或行。 更新2: 该index.php是一个文件夹中www.myadress.com/myfolder/index.php 我想拒绝访问该文件夹中的所有.php文件myfolder及其子文件夹。
77 php  .htaccess 

2
如何调用作为类变量的闭包?
class MyClass { var $lambda; function __construct() { $this->lambda = function() {echo 'hello world';}; // no errors here, so I assume that this is legal } } $myInstance = new MyClass(); $myInstance->lambda(); //Fatal error: Call to undefined method MyClass::lambda() 那么达到类变量的正确语法是什么?

7
TLD可能会持续多长时间?
我正在使用PHP开发电子邮件验证正则表达式,我需要知道TLD可能有效且仍然有效的时间。我进行了几次搜索,但找不到关于该主题的太多信息。那么一个TLD可能会持续多久?

7
如何建立RESTful API?
问题是这样的:我有一个在PHP服务器上运行的Web应用程序。我想为此构建一个REST API。 我进行了一些研究,发现REST api使用带有身份验证密钥(不一定)的某些URI的HTTP方法(GET,POST ...),并且信息以HTTP响应的形式返回,信息为XML或JSON。 (我宁愿使用JSON)。 我的问题是: 作为应用程序的开发人员,我如何构建这些URI?我需要在该URI上编写PHP代码吗? 如何构建JSON对象以作为响应返回?
77 php  api  rest  authentication 

10
PHP中的命令行密码提示
我正在编写一个命令行工具来帮助我的Web应用程序。需要密码才能连接到服务。我希望脚本显示密码提示,因此我不必将其作为命令行参数传递。 这很容易,但是我希望它在输入时不将密码回显到屏幕上。我该如何使用PHP? 使用纯PHP(no system('stty'))并用替换字符的好处*。 编辑: 该脚本将在Unix之类的系统(Linux或Mac)上运行。该脚本是用PHP编写的,很可能会一直保持这种状态。 另外,记录在案的stty方法是: echo "Password: "; system('stty -echo'); $password = trim(fgets(STDIN)); system('stty echo'); // add a new line since the users CR didn't echo echo "\n"; 我希望那里没有system()电话。
77 php  passwords 

27
Apache不在XAMPP控制面板上运行(错误:Apache意外关闭。这可能是由于端口被阻塞)
我已经在Windows 7上成功安装了XAMPP(xampp-win32-1.8.2-0-VC9-installer.exe)。但不幸的是,在从XAMPP控制面板运行Apache的过程中发现以下错误: 5:38:38 PM [Apache] Error: Apache shutdown unexpectedly. 5:38:38 PM [Apache] This may be due to a blocked port, missing dependencies, 5:38:38 PM [Apache] improper privileges, a crash, or a shutdown by another method. 5:38:38 PM [Apache] Press the Logs button to view error logs and check 5:38:38 PM …
77 php  apache  server  xampp  port 


2
在PHP中管理curl输出
如何隐藏PHP中curl的输出? 我的代码如下: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_USERPWD, PSSWDINFO); $result= curl_exec ($ch); curl_close ($ch); 问题是,它会喷出整个页面,我如何简单地显示“成功”或“失败”消息?
77 php  curl 

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.