I have a php application that saves the pictures on the server and also stores the picture names in the database . The issue that I have is that the picture names include the path/folder where it was saved from (e.g 1220368812/chpk2198933_large-2.jpg) so I need a str_replace pattern to remove “1220368812/” and have the picture name correct stored in the db .
Also I would appreciate if you will send me a good link that explains how exactly the str_replace patterns work or at least how the pattern that you use work .
I have a php application that saves the pictures on the server and also
Share
Try
basename— Returns filename component of pathExample #1 basename() example
There is no need to
str_replaceanything, becausebasenamewill remove the path part. Also,str_replacedoes not allow for patterns. All it does is replace all occurrences of the search string with the replacement string. Replacement by patterns is done with Regular Expressions, but they are not necessary here either.