$file_array=preg_replace('/\<(\d+)\>/','<img src="$1.jpg" />', $file_array); 

How to make the numbers be without the first 0? in the text <080> can be met, how instead of $ 1 = 080 get $ 1 = 80 ? if there is such a way)

    1 answer 1

    try rewriting it somewhere

     /\<0*(\d+)\>/','<img src="$1.jpg" /> 

    And turn on the greedy mode, if it is not included. The construction 0 * just captures leading zeros.

    • to know something else about the "greedy" regime)) and the idea is not bad) - Vladimir Klykov
    • in greedy mode, regulars capture characters to the maximum. that is, suppose we have such a regular season 0 * \ d + and such a line 00011 in the greedy mode 0 * captures all zeros. In the greedy - not one. If my memory serves me, then preg_replace is just in greedy mode and works in this case. - KoVadim
    • Thanks for the clarification of greed :) - Vladimir Klykov
    • In this particular situation, it is better to be super-greedy / jealous - timka_s