Php 如何修改preg_replace_回调模式以匹配<;p>;元素是否具有属性?

Php 如何修改preg_replace_回调模式以匹配<;p>;元素是否具有属性?,php,regex,Php,Regex,如何更改模式,使其与带属性或不带属性的p标记匹配?目前,它只匹配没有属性的p标记 $replaced_content = preg_replace_callback('#(<p>.*?</p>)#', 'p_callback', $content); $replaced_content=preg_replace_callback('#(*?)#','p_callback',$content); 示例内容#1: 测试测试测试?试验,试验,即。, 示例内容#2

如何更改模式,使其与带属性或不带属性的p标记匹配?目前,它只匹配没有属性的p标记

$replaced_content = preg_replace_callback('#(<p>.*?</p>)#', 'p_callback', $content);
$replaced_content=preg_replace_callback('#(*?

)#','p_callback',$content);
示例内容#1:



测试测试测试?试验,试验,即。,

示例内容#2


测试测试测试?试验,试验,即。,

使用修饰符:

根据多尔·谢默的评论编辑

$replaced_content=preg_replace_回调('#(].*?

)#s',p_回调',$content
使用修饰符:

根据多尔·谢默的评论编辑

$replaced_content=preg_replace_回调('#(].*?

)#s',p_回调',$content
虽然这看起来很吓人,但我认为这是最好的解决方案,除非你想开始做心理检查。+1我会改成
.*?

只是为了确保它不会从
标签或其他以pal开头的东西开始。虽然这看起来很吓人,但我认为这是最好的解决方案,除非你想开始做心理检查所有环顾四周。+1我将更改为
].*?

只是为了确保它不会以
标记或其他以p开头的内容开头
<div style="margin: 10px 0;">
    <a href="test.jpg" target="_blank" rel="nofollow">
        <img style="float: left; margin: 10px; max-width: 25%;" title="test" src="test.jpg" alt="test" />
    </a>
    <p>
        <a href="test" target="_blank" rel="nofollow">
            <img title="PDF file" src="test.png" alt="PDF file" /> 
            <span style="font-weight: bold; text-transform: capitalize;">Test ...</span>
        </a>
        <span>test <strong>test</strong> test? test, test, i.e., </span>
        <a href="test.pdf" target="_blank" rel="nofollow"> ... Get Content Here</a>
    </p>
</div>
<div style="margin: 10px 0;">
    <a href="test.jpg" target="_blank" rel="nofollow">
        <img style="float: left; margin: 10px; max-width: 25%;" title="test" src="test.jpg" alt="test" />
    </a>
    <p style="margin:10px; float:left">
        <a href="test" target="_blank" rel="nofollow">
            <img title="PDF file" src="test.png" alt="PDF file" /> 
            <span style="font-weight: bold; text-transform: capitalize;">Test ...</span>
        </a>
        <span>test <strong>test</strong> test? test, test, i.e., </span>
        <a href="test.pdf" target="_blank" rel="nofollow"> ... Get Content Here</a>
    </p>
</div>
$replaced_content = preg_replace_callback('#(<p[\s>].*?</p>)#s', 'p_callback', $content