dqlhsm9820 2013-12-02 08:21
浏览 44
已采纳

Preg按字符和每个换行符分割

I am using preg_split, with "u" modifier to split to the characters in php. I have the problem that the newline carriages are not splitted in a single entry, so useing this line:

preg_split('//u',"a töxt
{{image}}", -1,PREG_SPLIT_NO_EMPTY);

I get the following result for example:

   Array (
    [0] => a
    [1] =>  
    [2] => t
    [3] => ö
    [4] => x
    [5] => t
    [6] =>  { //this line is orginally wrapped and not a space
    [7] => {
    [8] => i
    [9] => m
    [10] => a
    [11] => g
    [12] => e
    [13] => }
    [14] => } )

If i am encoding the string before for checking the valid chars i get:

Array
(
    [data] => töxt
{{image}}
    [chars] => {t}{�}{�}{x}{t}{
}{{}{{}{i}{m}{a}{g}{e}{}}{}}
    [hex] => {74}{C3}{B6}{78}{74}{0A}{7B}{7B}{69}{6D}{61}{67}{65}{7D}{7D}
    [mb_chars] => {t}{ö}{x}{t}{
}{{}{{}{i}{m}{a}{g}{e}{}}{}}
    [mb_hex] => {74}{F6}{78}{74}{0A}{7B}{7B}{69}{6D}{61}{67}{65}{7D}{7D}
)

So any idea how to achieve the result.. It is not only the carriage return but it is the most important actually..

It is a requirement to handle also multibyte characters

  • 写回答

2条回答 默认 最新

  • doupinwan0563 2013-12-04 17:55
    关注

    Now I found a solution for myself to solve my problem:

    $arr_content = preg_split("/(.|\\\
    )/u",$html_cont, -1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
    

    Thanks to anybody who helped finding the trouble ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?