I need to replace in a php file some text from DB with preg_replace. The string to replace is:
images/
and change it to
cms/images/
I know it’s simple but I just can’t understand this syntax.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since the OP requested a solution using
preg_replace()here’s one. Otherwise the solution of @genesis is more than suitable.$new_string = preg_replace('#images/#i', 'cms/images/', $string);The above simply replaces
images/withcms/images/in$string. The # symbols are delimiters which separate the expression from the modifiers. In this case theimages/andirespectively. Theimakes it case insensitive.