php regular expression to convert string followed by number into multiple strings each followed by one of the digits

前端 未结 2 1735
南旧
南旧 2021-01-27 03:02

how to i replace

Apple 123456

to

Apple 1|Apple 2|Apple 3|Apple 4|Apple 5|Apple 6

by php pcre?

2条回答
  •  孤街浪徒
    2021-01-27 03:35

    With this one you get partially what you want:

    That results in: Apple Apple 1|Apple 2|Apple 3|Apple 4|Apple 5|Apple 6|

    For removing the first "Apple" you could str_replace() or explode() the initial string, resulting something like

    The result here is Apple 1|Apple 2|Apple 3|Apple 4|Apple 5|Apple 6|. You can remove the last pipe by using substr($result, 0, -1).

    The final code will look like this:

提交回复
热议问题