从正则表达式中获取数字并添加该空格数

时间:2013-09-14 10:20:18

标签: php regex

<p style="margin-left:5px"><em>6.1. pH changes</em></p>

我希望5 5px <p><em> $result = preg_replace('#<p style="margin-left:[\s]?\.([0-9])[0-9]?in"><em>#','<p><em>[&nbsp;]{$1}',$string); 之后添加{{1}}个空格 标签

我使用了以下但无济于事。

{{1}}

请在这方面提供帮助。将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以尝试以下操作:

$result = preg_replace_callback('#<p\s*style="margin-left:(?P<SpaceCount>[0-9]+)[^>]*><em>#', function($matches) { return '<p><em>' . str_repeat('&nbsp;', intval($matches['SpaceCount'])); }, '<p style="margin-left:5px"><em>6.1. pH changes</em></p>');
相关问题