-1

Web ソースからデータを取得していますが、多くの場合、データの形式が適切ではありません。次のように返されるテキストをクリーンアップしたい:

Featuring six amazing National Parks: Glacier,
Waterton Lakes, Yellowstone, Grand Teton, Arches, and Canyonlands.

Your tour begins in Chicago where you will board
the Empire Builder
bound for the first National Park on your trip, Glacier, where you will explore the famed Going-to-the-Sun Road and enjoy a full-day excursion to
Waterton Lakes National Park in Canada (passport required).

単一の改行を取り除きたいが、二重の改行は保持したい。これはPHPでどのように行うことができますか? 理想的には、文字列は次のようになります。

Featuring six amazing National Parks: Glacier, Waterton Lakes, Yellowstone, Grand Teton, Arches, and Canyonlands.

Your tour begins in Chicago where you will board the Empire Builder bound for the first National Park on your trip, Glacier, where you will explore the famed Going-to-the-Sun Road and enjoy a full-day excursion to Waterton Lakes National Park in Canada (passport required).

試してみpreg_replace( "/\r|\n/", "", $string);ましたが、これにより、単一の改行だけでなく二重の改行も削除されます。

4

2 に答える 2