Please help me correct the regular expression for the preg_split() function.

 preg_split('/^(photo)*([0-9])+_/','photo1542_123') 

It is necessary that the string photo1542_123 broken into an array

 `Array ( [0] =>photo [1] => 1542 [2] => 123 ) `. 
  • I think you need preg_match, only there will be another extra zero element with the whole line - Mike
  • one
    Mike is right preg_match('/^(photo)(\d+)_(\d+)$/','photo1542_123', $m) should return what is needed in $m[1] - cyadvert
  • cyadvert Thank you! - withoutname
  • @ wao138, And where are the lines of this format? Not id photo in VK? Just interesting))) - Dmitriy Simushev
  • Dmitriy Simushev course project, and this option of storing the storage of id photos in html code seemed to me the most acceptable)) - withoutname

1 answer 1

Well then I will issue as an answer :)

 preg_match('/^(photo)(\d+)_(\d+)$/','photo1542_123', $m) 

returns what you need in $m[1]