时间:2021-07-01 10:21:17 帮助过:27人阅读
代码如下:
< ?php
//字符串
$string = "Name: {Name}< br>\nEmail:
{Email}< br>\nAddress: {Address}< br>\n";
//模式
$patterns =array(
"/{Address}/",
"/{Name}/",
"/{Email}/"
);
//替换字串
$replacements = array (
"No.5, Wilson St., New York, U.S.A",
"Thomas Ching",
"tom@emailaddress.com",
);
//输出模式替换结果
print preg_replace($patterns,
$replacements, $string);
?>
代码如下:
public static String PregReplace(this String input, string[] pattern, string[] replacements) {
if (replacements.Length != pattern.Length) throw new ArgumentException("Replacement and Pattern Arrays must be balanced");
for (var i = 0; i < pattern.Length; i++)
{ input = Regex.Replace(input, pattern[i], replacements[i]); }
return input;
}
以上就介绍了jsreplace c#中的实现php中的preg_replace,包括了jsreplace方面的内容,希望对PHP教程有兴趣的朋友有所帮助。