php - Preg_Replace Options -


i'm trying add in middle of text, that.

privateimg-0123456789_[i wanna add here something].jpg

and don't know function or way should use.

i wondering function preg_replace, don't know if can make function replace specific text in position.

just use str_replace()?

$string = "privateimg-0123456789.jpg"; echo str_replace(".jpg", "[whateveryouwant].jpg", $string); 

if must use regex:

$string = "privateimg-0123456789.jpg"; echo preg_replace("/\.(jpe?g|png|gif)$/si", "[whateveryouwant].$1", $string); 

this jpg, jpeg, png , gif, long last part. /foo/bar.gif/thisisweird wont match


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -