Reputation: 589
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.
Upvotes: 0
Views: 2251
Reputation: 26467
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/
with cms/images/
in $string
. The # symbols are delimiters which separate the expression from the modifiers. In this case the images/
and i
respectively. The i
makes it case insensitive.
Upvotes: 0