PHP preg_replaceを使用してCSVファイル内の改行を削除しようとしました。 私はそれを取得しません。私はたくさん試しました。誰かが私のコードを手伝ってくれるかもしれません。CSV内のpreg_replaceでLFを削除
$content = "Halvah sweet ice.|Donut pastry candy canes bear claw toffee ice cream
cotton candy jelly-o. Pastry chocolate lemon drops biscuit muffin muffin apple pie croissant. Candy canes topping pudding biscuit. Cotton candy sweet mi bears chocolate. Croissant sesame snaps chocolate cake. Topping toffee oat cake cake. Biscuit| cheesecake powder";
$content = preg_replace('/^\|(.*)\n(.*)\|$/', "", $content);
// expected result
$content = "Halvah sweet ice.|Donut pastry candy canes bear claw toffee ice cream cotton candy jelly-o. Pastry chocolate lemon drops biscuit muffin muffin apple pie croissant. Candy canes topping pudding biscuit. Cotton candy sweet mi bears chocolate. Croissant sesame snaps chocolate cake. Topping toffee oat cake cake. Biscuit| cheesecake powder";
|例えば、 "クリーム"という単語の後の改行。
ありがとうございます!
注意:* preg_replace():行6の/home/kVVTYTY/prog.phpで未知の修飾語 '\'が表示される* –
['$ content = preg_replace_callback("/\ | ($ m){\t return str_replace(配列( "\ n"、 "\ r")、 ""、$ m [0]); }、$ content) ; '](https://ideone.com/J0tdns)。 –
@WiktorStribiżewあなたが正しいです、私は古いコードバージョンを使用しました。私はスタックで/ \\\\ n /というサンプルを見つけました。そして、\ nが正しいかどうかをエスケープするようにしました。 – vine