Greetings.

Please tell me with a template for a replace ... there are links:

/upload/blablabla/mainbla/bla/NeobyichnoeiskusstvoFingerpainting.Slon3232.jpg /upload/blablabla/mainbla/bla1/RSRRSRRyoSSSS.png 

need to make them

 /upload/blablabla/mainbla/bla/min/NeobyichnoeiskusstvoFingerpainting.Slon3232_min.jpg /upload/blablabla/mainbla/bla1/min/RSRRSRRyoSSSS_min.png 

variant preg_replace("/\.(jpg|jpeg|png|gif)/i","_min.\\1",$str); changes only the file name, and how would you add the min folder in front of the name? :) thank you in advance.

    1 answer 1

     preg_replace("/(?:\/)([^\/]+\.(?:jpg|jpeg|png|gif))/i","/min/$1",$str) 

    to change the file name too

     preg_replace("/(?:\/)([^\/]+)(\.(?:jpg|jpeg|png|gif))/i","/min/$1_min$2",$str) 
    • thanks cool) but in this version only the folder in front of the file name is substituted. but the name itself does not change :) - Jenyok
    • @Jenyok added in reply - Stanislav Grotto
    • @Jenyok if you have one point only in the extension, then you can and so str_replace('.','_min.',$str) - Naumov