我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何使用php拆分字符串的数量和字符? [重复]

This question already has an answer here:

  • How to separate letters and digits from a string in php 8 answers

I would like to know how to split number and character into string in PHP. for example. I have string B234CR45SV42 and I wan to split into

B 
234 
C 
R
45
SV
42

Please note that my code will change different character and numbers any time.

</div>

Use regex in preg_match_all() function to select target parts of string.

$str = "B234CR45SV42";
preg_match_all("/[A-Z]+|\d+/", $str, $matches);
print_r($matches[0]);

See result in demo

近期文章

  • 如何将html转换为一个行字符串?
  • asp小说网站源码,运行环境vs2010,登录注册,前台+后台
  • 如何在mysql中使用calculate连接查询?
  • 提交表单并重定向到另一个视图
  • PHP循环手动创建JSON
  • 试图从php调用js函数并传递php html字符串作为参数
  • windows php 64位系统ATM
  • 使用php为文件提供随机名称
  • 看不出为什么错误是MethodNotAllowedHttpException
  • 要求用户登录某些页面
  • 我如何重组数组
  • ORDER BY FIELD(id,?)无法在PDO中工作
  • PHP时间和日期功能不起作用
  • substr()PHP不适用于数组元素
  • codeigniter形式响应为json
  • 对PHP上的SQL表使用DELETE
  • 如何删除输入文件表格上方的标签?
  • 客户帐户暂时禁用magento
  • php代码使用pincode查找城市,州和国家名称
  • set_value函数在codeIgniter 3中不起作用

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华