如何使用 preg_replace php 删除字符串中的 font-family 样式?
我尝试使用此代码,但不起作用。我怎样才能做到这一点?
<?PHP
if(isset($_POST["submit"]))
{
$editor = $_POST['editor'];
$editor = preg_replace("#font-family(.*?)>(.*?);#is", "", $editor);
echo $editor;
}
?>
<form class="form" method="post" action="" ENCTYPE = "multipart/form-data">
<textarea name="editor" style="margin: 0px;width: 415px;height: 30px;" ><p style="font-family: fantasy; font-size: 34px;">test</p></textarea>
<br>
<input type="submit" name="submit" value="OK">
</form>
最佳答案
font-family.+?;
将匹配“font-family: Fantasy;”在你的情况下。您只需将其替换为空字符串即可。你的正则表达式字符串对我来说毫无意义。
也许这会帮助您比我能解释的更好地理解问题所在 https://regex101.com/
看来您在理解正则表达式时遇到了一些困难。
LE:你的代码应该是。
if(isset($_POST["submit"]))
{
$editor = $_POST['editor'];
$editor = preg_replace('/font-family.+?;/', "", $editor);;
echo $editor;
}
关于php - 如何使用 preg_replace php 删除字符串中的 font-family 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41198169/