Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要使用 php/regex 来替换它:
{{image-4-m}}
对此:
<img src="4.jpg" class="m" />
或者另一个例子,这个:
{{image-53-v}}
<img src="53.jpg" class="v" />
我将如何做到这一点?
preg_replace您可以通过使用索引来引用组$n。
preg_replace
$n
preg_replace('/{{image-(\d+)-([mv])}}/', '<img src="$1.jpg" class="$2" />', $template);
这是一个演示。