PHP将字符串转为数组

By | 2015年4月30日

直接看代码吧

$str   = '早在2008年,红旗曾展示了旗下的全新SUV概念车,该车在设计上融入了很多中国元素,例如天安门、戈之类的中国文化符号。按照红旗的规划,这款SUV将有望在2015年左右正式推出。而在本届上海车展上,我们确实看到了它的身影。';
$arr = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
print_r($arr);

结果如下

Array
(
    [0] => 早
    [1] => 在
    [2] => 2
    [3] => 0
    [4] => 0
    [5] => 8
    [6] => 年
    [7] => ,
    [8] => 红
    [9] => 旗
    [10] => 曾
    [11] => 展
    [12] => 示
    [13] => 了
    [14] => 旗
    [15] => 下
    [16] => 的
    [17] => 全
    [18] => 新
    [19] => S
    [20] => U
    [21] => V
    [22] => 概
    [23] => 念
    [24] => 车
    [25] => ,
    [26] => 该
    [27] => 车
    [28] => 在
    [29] => 设
    [30] => 计
    [31] => 上
    [32] => 融
    [33] => 入
    [34] => 了
    [35] => 很
    [36] => 多
    [37] => 中
    [38] => 国
    [39] => 元
    [40] => 素
    [41] => ,
    [42] => 例
    [43] => 如
    [44] => 天
    [45] => 安
    [46] => 门
    [47] => 、
    [48] => 戈
    [49] => 之
    [50] => 类
    [51] => 的
    [52] => 中
    [53] => 国
    [54] => 文
    [55] => 化
    [56] => 符
    [57] => 号
    [58] => 。
    [59] => 按
    [60] => 照
    [61] => 红
    [62] => 旗
    [63] => 的
    [64] => 规
    [65] => 划
    [66] => ,
    [67] => 这
    [68] => 款
    [69] => S
    [70] => U
    [71] => V
    [72] => 将
    [73] => 有
    [74] => 望
    [75] => 在
    [76] => 2
    [77] => 0
    [78] => 1
    [79] => 5
    [80] => 年
    [81] => 左
    [82] => 右
    [83] => 正
    [84] => 式
    [85] => 推
    [86] => 出
    [87] => 。
    [88] => 而
    [89] => 在
    [90] => 本
    [91] => 届
    [92] => 上
    [93] => 海
    [94] => 车
    [95] => 展
    [96] => 上
    [97] => ,
    [98] => 我
    [99] => 们
    [100] => 确
    [101] => 实
    [102] => 看
    [103] => 到
    [104] => 了
    [105] => 它
    [106] => 的
    [107] => 身
    [108] => 影
    [109] => 。
)

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据