如何转动
$str = "Shoes cost $10, and pants cost $25obo";
到
$str = "Shoes cost <em>$10></em>, and pants cost <em>$25obo</em>";
使用php。我需要一种对许多文本都有效的方法,比如许多段落,而不仅仅是一个句子。
答案 0 :(得分:1)
还有其他方法可以使用PHP,但您可以使用REGEX
preg_replace()
模式的这种方式
<强> CODE 强>
$re = "/(\\$\\d+\\w*)/";
$str = "Shoes cost \$10, and pants cost \$25obere\nShoes cost \$10, and pants cost \$25obe \nShoes cost \$10, and pants cost \$25obfe\nShoes cost \$10, and pants cost \$25obee\n Shoes cost \$10, and pants cost \$25obo";
$subst = "<em>$1</em>";
$result = preg_replace($re, $subst, $str);
print $result;
<强>输出强>
Shoes cost <em>$10</em>, and pants cost <em>$25obo</em>
Shoes cost <em>$10</em>, and pants cost <em>$25TE</em>
Shoes cost <em>$10</em>, and pants cost <em>$25ded</em>
Shoes cost <em>$10</em>, and pants cost <em>$25o</em>
Shoes cost <em>$10</em>, and pants cost <em>$25obo</em>