php - How to replace all, and then add a numbering sequence marking replacements? -
Hi, I have an example file name: losangeles.php 2252 times and I want to convert it to losangeles-0001.php , Losangeles-0002.php, losangeles-0003.php and so on, losangeles-2252.php, how is it done?
Thank you!
$ str = & lt; & Lt; & Lt;
EOF losangeles.php losangeles.php losangeles.php EOF; $ Str = preg_replace_callback ('#' B (Los Angeles) (? = \.) # I ', create_function (' $ m ',' fixed $ i = 1; return $ m [1] .sprintf ("-% 04d" , $ I ++); '), $ str); Copy $ str "\ N";
Output:
Lessangles-0001.php Los Angeles-20002.php losangeles-0003.php
Live Demo:
Comments
Post a Comment