怎么在php中加入换行符,在PHP中使用sprintf时添加\ n换行符号

我试图将现有数据从MySQL数据库导出到ruby命令中,我可以使用rake db:seed运行。在PHP中使用sprintf时添加 n换行符号

这是我的代码。

# Generate db:seed data for proveedores.

$proveedores = R::findAll('tbproveedores');

$proveedoresE = R::exportAll($proveedores);

foreach ($proveedoresE as &$p) {

$line = 'BookSupplier.create(company: "%s", city: "%s", country: "%s", address: "%s", telephone: "%s", contact: "%s", email: "%s", website: "%s"\n';

$exportedLine = sprintf($line, $p['empresa'], $p['ciudad'], $p['pais'], $p['direccion'], $p['telefono'], $p['personacontacto'], $p['email'], $p['website']);

var_dump($exportedLine);

fwrite($seeds, $exportedLine);

echo "
";

}

注意$ line变量末尾的\n换行符号。我在网上阅读,这是使用换行符所需的全部内容。

我的代码的输出上面(vertabim,长线):

BookSupplier.create(company: "Pearson", city: "Lima", country: "Peru", address: "Av. Limon", telephone: "4673535421", contact: "Javier", email: "", website: ""\nBookSupplier.create(company: "Project Management Institute - PMI", city: "Pennsylvania", country: "Estados Unidos", address: "Newtown Square, Pennsylvania", telephone: "1", contact: "Limberg Morales", email: "", website: "http://www.pmi.org/"\nBookSupplier.create(company: "UVirtual - Centro de Excelencia", city: "Santa Cruz", country: "Bolivia", address: "Av. Irala 585", telephone: "1", contact: "Limberg Morales", email: "", website: ""\nBookSupplier.create(company: "Ábaco de Rodolfo Depalma", city: "Buenos Aires", country: "Argentina", address: "Viamonte 1336, 4° (C1053 ACB) Buenos Aires", telephone: "5411-43711675", contact: "Limberg Morales", email: "", website: "http://www.abacoeditorial.com.ar/"\nBookSupplier.create(company: "Pablo Lledó - ProjectManagement", city: "Canadá", country: "Estados Unidos", address: "Victoria, BC, Canadá", telephone: "1", contact: "Limberg Morales", email: "", website: ""\n

我想每个呼叫是在它自己的路线,下面我换行插入。任何建议我做错了什么?

2013-02-26

sergserg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值