【问题标题】:PHP syntax with file_put_contents带有 file_put_contents 的 PHP 语法
【发布时间】:2014-09-03 12:47:25
【问题描述】:

我试着放

  $string .= '(\''.$idURL.'\', \''.$premierP.'\', \''.$prefixe.'\', \''.$matches1['0'].'\', \''.$matches2[0].'\'),\\n';

在带有file_put_contents($file, $string); 的文件(用于构造sql 行)中,但它不起作用,怎么了?

【问题讨论】:

  • 这没有什么问题,除了可能双重转义 \n 并将其放在单引号内而不是双引号(\n 单引号)
  • 您知道可以将单引号与双引号混合使用以避免反斜杠混乱吗?即 `foo(" 'bar' ")` (所以打破了这个)而不是foor(' \'bar\' ')
  • 定义“不起作用”。这意味着什么?它做什么?有什么错误吗? 有什么

标签: php syntax


【解决方案1】:

这对我有用。我已经进行了如下测试。

<?php 

$file = 'test.txt';
$idURL ='test';
$premierP = 'test';
$prefixe = 'test';
$matches1['0'] = 'test';
$matches2[0] = 'test';
$string .= '(\''.$idURL.'\', \''.$premierP.'\', \''.$prefixe.'\', \''.$matches1['0'].'\', \''.$matches2[0].'\'),\\n';

file_put_contents($file, $string);
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    相关资源
    最近更新 更多