如何使用preg_替换php删除字符串中的字体族样式?

如何使用preg_替换php删除字符串中的字体族样式?,php,css,Php,Css,如何使用preg_替换php删除字符串中的字体族样式 我试图使用此代码,但没有成功。我该怎么做 <?PHP if(isset($_POST["submit"])) { $editor = $_POST['editor']; $editor = preg_replace("#font-family(.*?)>(.*?);#is", "", $editor); echo $editor; } ?> <form class="form" method

如何使用preg_替换php删除字符串中的字体族样式

我试图使用此代码,但没有成功。我该怎么做

<?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>

测试


将匹配“字体系列:幻想;”就你而言。您可以用空字符串替换它。你的正则表达式字符串对我来说毫无意义

也许这比我能解释的更能帮助你理解什么是错的

看来你理解正则表达式有点困难

乐:你的代码应该是

if(isset($_POST["submit"]))
{
    $editor = $_POST['editor'];
    $editor = preg_replace('/font-family.+?;/', "", $editor);;
    echo $editor;
}

“#”应该做什么?@TigOldBitties
preg_replace
需要在regexp周围使用分隔符。它可以是任何角色,他使用的是
#
@Barmar即使是这样,它仍然是错误的。我只是从来没见过。最后的“是”是什么?正如我所说,在他提供的上下文中,这对我来说没有意义。
是修饰标志
i
表示不区分大小写,
s
表示
可以匹配换行符。警告:preg_replace():分隔符不能是字母数字或反斜杠$editor=preg_replace(“font-family.+?;”,“”,$editor);你在开玩笑吧?preg_replace(“/font-family.+?;/”,“,$editor);阅读文档,伙计。我们怎样才能得到两行文字?
if(isset($_POST["submit"]))
{
    $editor = $_POST['editor'];
    $editor = preg_replace('/font-family.+?;/', "", $editor);;
    echo $editor;
}