dongre6270 2017-11-18 14:02
浏览 58
已采纳

如何在特定文本拆分后获得未分割文本结果

I have this code below

$txt = "12345678910";

$start = preg_split("/5/", $txt); 

$split = str_split($start[1], 2);

echo implode(',', $split);

echo $start[0];

Which start text split from 5 example 67, 89, 10 in my achievement, I want to be able get the let unsplit text and the split text also example my result show look like: 67, 89, 10 and 12345 thanks for understanding and impact in my soluction.

  • 写回答

2条回答 默认 最新

  • douchuanchai2793 2017-11-18 14:24
    关注

    Try like this, It'll work as per your requirement. :) I just used explode() instead of first preg_split()

    $num = 5;
    $txt = "12345678910";
    $length = strlen($txt);
    $initial = substr($txt, 0, $num);
    $explode = explode($num, $txt); 
    $result = str_split($explode[1], 2);
    array_push($result,$initial);
    echo implode(',', $result);
    

    Edit: As per comment

    $num = 5;
    $array_var = [];
    $txt = "12345678910";
    $length = strlen($txt);
    $initial = substr($txt, 0, $num);
    $explode = explode($num, $txt); 
    $result = str_split($explode[1], 2);
    $array_var[] = implode(',',$result);
    $array_var[] = $initial;
    list($firstvar, $secondvar) = $array_var;
    echo "First variable = $firstvar and Second variable $secondvar";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路