php - Combining two preg_replace into one -


I want to add those 2 preg_replace to one. For example 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

How can I do this?

Edit

I think I have expressed myself wrongly

.jpg to only data-thumb-bg = has been changed. As you change the data-thumb-bg , you replace .jpg with data-thumb-bg

Kind regards

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

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -