php - 如何使用 preg_replace php 删除字符串中的 font-family 样式?

标签 php css

如何使用 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/

相关文章:

php - 将 jquery 值分配给 php 变量

php - 谷歌电子表格 API : memory exceeded

php - 我如何解码 laravel 5 中的哈希值?

javascript - 如何将.csv 中的数据加载到数据表中?

css - 如何为 Django 中的所有内置表单小部件设置默认 css 类

php - 如何在不重新加载页面的情况下运行php函数

php - 在 MySQL 中更新表行的问题

jquery - 为什么粘性导航在 'sticks' 时会改变宽度?

css - nth-of-type 在 IE 9 中不起作用

jquery - 我的幻灯片在主机上不起作用