更换的第一个HTML 标签我在PHP中的文本字符串:如何在PHP
<strong> MOST </strong> of you may have a habit of wearing socks while sleeping.
<strong> Wear socks while sleeping to prevent cracking feet</strong>
<strong> Socks helps to relieve sweaty feet</strong>
我们可以看到,第一强标签
<strong> MOST </strong>
我想删除第一强大的标签,并在它内部使用ucwords(首字母大写)。这样的结果
Most of you may have a habit of wearing socks while sleeping.
<strong> Wear socks while sleeping to prevent cracking feet</strong>
<strong> Socks helps to relieve sweaty feet</strong>
我已经尝试过爆炸功能,但它看起来不像我想要的。这里是我的代码
<?php
$text = "<strong>MOST</strong> of you may have a habit of wearing socks while sleeping. <strong> Wear socks while sleeping to prevent cracking feet</strong>. <strong> Socks helps to relieve sweaty feet</strong>";
$context = explode('</strong>',$text);
$context = ucwords(str_replace('<strong>','',strtolower($context[0]))).$context[1];
echo $context;
?>
我的代码只能导致
Most of you may have a habit of wearing socks while sleeping. <strong> Wear socks while sleeping to prevent cracking feet
1对于使用'preg_replace_callback'功能。但它应该是'return ucfirst(strtolower($ a [1]));'因为第一个匹配'最'是全部大写,所以你需要首先降低它,然后'ucfirst'它。此外,您需要将第四个参数传递给'preg_replace_callback' - 限制为1,因为该问题只想删除第一个'strong'标记。 – Chris