如何根据PHP中的空格字符制作多行到单行? [英] How to make multi line to single line based on space character in PHP?

查看:75
本文介绍了如何根据PHP中的空格字符制作多行到单行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例档案:



 Aiken,L。S.,& West,S。G.(1991)。多元回归:测试和解释
互动。贤者出版社。
Bai,X.,Yao,W。,& Boyer,J。E.(2012)。混合回归的稳健配置
模型。计算统计&数据分析,56(7),2347-2359。
Bartolucci,F。,& Scaccia,L。(2005)。使用混合物处理
非正态回归误差。计算统计&数据分析,
48(4),821-834。





如果我做

文件(示例)

,考虑如下:



第1行 - 艾肯,LS,& West,S。G.(1991)。多元回归:测试和解释
第二线 - 互动。 Sage Publications



但它应该在一行中。因此,我需要根据第二行所具有的空间将这两行作为单行。因此我需要构建所有引用列表。



如果我喜欢这个,



 $ data = str_replace(\\\\ n,,$ data); 



然后所有行都将变为单行。我希望每个引用都是单行。



我试过了,

 $ f =文件(示例)
for($ i = 0; $ i< count($ f); $ i ++){
$ f [$ i] = str_replace(\\\\ n,,$ f [$ i]);
????
//应该将新行字符串替换为单行直到它在
//新行字符串中找不到空格,以便我可以在第二行中构造第二个引用,因此
//上。
}

解决方案

data = str_replace(\\ n,,

数据);



然后所有行都将变为单行。我希望每个引用都是单行。



我试过了,

 


f = file(example )
for(


Example file:

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.



If I do

file("example")

,Its considering like below:

1st line- Aiken, L. S., & West, S. G. (1991). Multiple Regression: Testing and Interpreting
              2nd line- interactions. Sage Publications


but it should be in a single line. So, I need to make that two lines as single line based on the space which second line have.As such I need all the reference list to be structured.

If I do like this,

$data = str_replace("\r\n", "", $data); 


then all the lines will become as single line. I want each reference to be single line.

I tried,

$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_replace("\r\n", "",


data);


then all the lines will become as single line. I want each reference to be single line.

I tried,


f=file("example") for(


这篇关于如何根据PHP中的空格字符制作多行到单行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆