如何在PHP中基于空格字符将多行转换为单行?

如何在PHP中基于空格字符将多行转换为单行?,php,string,Php,String,示例文件: Aiken, L. S., & West, S. G. (1991). Multiple Regression: Testing and Interpreting interactions. Sage Publications. Bai, X., Yao, W., & Boyer, J. E. (2012). Robust fitting of mixture regression models. Computational Statistics

示例文件:

Aiken, L. S., & West, S. G. (1991). Multiple Regression: Testing and Interpreting
      interactions. Sage Publications.
Bai, X., Yao, W., & Boyer, J. E. (2012). Robust fitting of mixture regression
      models. Computational Statistics & Data Analysis, 56 (7), 2347-2359.
Bartolucci, F., & Scaccia, L. (2005). The use of mixtures for dealing with
      non-normal regression errors. Computational Statistics & Data Analysis,
      48 (4), 821-834.
如果我做一个例子,它考虑如下:

1st line- Aiken, L. S., & West, S. G. (1991). Multiple Regression: Testing and Interpreting
          2nd line- interactions. Sage Publications
但它应该在一行中。所以,我需要根据第二行所具有的空间,将这两行作为单行。因此,我需要对所有参考列表进行结构化

如果我真的喜欢这个

$data = str_replace("\r\n", "", $data); 
然后所有的线都会变成 作为单行线。我希望每个引用都是单行的

我试过了

$f=file("example")
for($i=0;$i<count($f);$i++){
$f[$i] = str_replace("\r\n", "", $f[$i]);
????
//should replace the new line strings to single line til it finds no space in the
 //new line string so that i can structure second reference in a second line and so
 //on.
}
它看起来像$data=str\u replace\r\n,,$data;或$data=str\u replace\n,,$data;你应该照顾好它。也就是说,如果这实际上是6个6的空间。只要它是一致的,你可以纠正我的间距,如果我弄错了

编辑: 试试这个:

$f=file_get_contents("example");
$f=str_replace("\n      ", " ", $f);
$f=explode("\n",$f);
...

如何将两行作为单个数据解析为str_replace\r\n,,$data。例如,在第一个引用中,两行是替换新行字符的数据。因此,如果我使用文件,它将第一行作为单个数据,第二行作为第二个数据,因此如何替换这两行之间的新行字符