如何用PHP删除回车?

时间:2013-12-28 13:52:03

标签: php mysql regex shell

我在代码ex:

中有一个带回车符的脚本
$q = $this->db->prepare("\n\t\t\tINSERT INTO hb_orders(`id`,`number`,`payment_module`,`client_id`,`invoice_id`,\n\t\t\t`total`,`date_created`,`status`,`order_ip`,`notes`) VALUES (\n\t\t\t'',:number,:module,:client,:invoice,\n\t\t\t:total,:date,:status,:ip,:notes\n\t\t\t)\n\t\t");


$q = $this->db->prepare("SELECT dom.*, p.options as tld_options, p.ns as tld_ns, p.nsips as tld_nsip FROM hb_domains dom\r\n            LEFT JOIN hb_domain_prices p ON p.product_id=dom.tld_id\r\n            WHERE dom.id=?  LIMIT 1");

$query = "SELECT mc.*, mc.settings as module_config FROM hb_modules_configuration mc\r\n                WHERE mc.active='1' AND (mc.settings LIKE '%isobserver%' ";

如何用PHP代码删除所有内容?

谢谢。

2 个答案:

答案 0 :(得分:2)

查看str_replace() function

$a = str_replace(array("\n", "\t"), '', $a);

这将从\n字符串中删除每个\t$a(并实际替换它们。)

答案 1 :(得分:1)

您可以使用:

$str = preg_replace("/[\n\r]/", "", $str);