本文介绍了如何通过php中的正则表达式多次替换分隔符之间的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想替换多个匹配的特定前缀和后缀分隔符之间的动态字符串值。通过在php中使用preg_replace()方法,我可以使用以下模式在分隔符之间设置值。但它只适用于最后一场比赛。

_________________________________________________________________________________________

preg_replace(#(。*)$ delimit(。*?)$ delimit(。*)#is, $ 1 $ attr = $ delimit $ inject $ delimit $ 3,$ contents);

_________________________________________________________________________________________

请帮帮我,我该怎样才能做到这一点。以及如何处理分隔符之间不可预测的空白



********* {delimiter} {old string} {delimiter} ***** ******* {delimiter} {old string} {delimiter} *****************

to

********* {delimiter} {new string} {delimiter} *********** {delimiter} {new string} {delimiter} ******* **********

请帮帮我。谢谢。

I want to replace dynamic string value between certain prefix and suffix delimiter for multiple match. By using preg_replace() method in php I can set value between delimiter with following pattern. but it only works for last match.
_________________________________________________________________________________________
preg_replace("#(.*)$delimit(.*?)$delimit(.*)#is", "$1$attr=$delimit$inject$delimit$3", $contents);
_________________________________________________________________________________________
Please help me, how can I achieve this. and how to handle unpredictable white space between delimiter

"********* {delimiter} {old string} {delimiter}************{delimiter} {old string} {delimiter} *****************"
to
"*********{delimiter} {new string} {delimiter}***********{delimiter} {new string} {delimiter}*****************"
Please help me.Thanks alot.

推荐答案




这篇关于如何通过php中的正则表达式多次替换分隔符之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 04:51