php - Combining two preg_replace into one -
I want to add those 2 preg_replace to one. For example How can I do this? Edit I think I have expressed myself wrongly Kind regards data-thumb-bg = "
with
style =" background-image: url ('
and followed by if .jpg
replace it with , .jpg);
. $ Input = preg_replace ('# data-thumb-bg = "# s',' style =" background-image: url (', $ input); $ input = preg_replace (' # .jpg # s', '.jpg);', $ input); // This will be executed only when one of the above matches .jpg
to only data-thumb-bg =
has been changed. As you change the data-thumb-bg
, you replace .jpg
with data-thumb-bg
I assume that your ultimate goal is to change the attribute of an element < Code> data-thumb-bg = "photo.jpg" to style = "background-image: url (photo.jpg);"
This can be used one more (note that since we do not use .
is unnecessary):
$ input = Preg_replace ('/ data-thumb -bg =' ([^ "] + /", 'style = "background-image: url (\ 1);"', $ input);
< P> If you only want to allow, you can use this expression:
data-thumb-bg = "([^ "+ ... .jpg]"
Or if you only want to allow, you can use an expression like this:
date -thnb-BG = "([^"] +? \. (?: Jpe? G | png | gif)) "
Comments
Post a Comment