Reputation: 89
How to using preg_replace php for remove font-family style in string ?
I tried to use this code , but not work. How can i do that ?
<?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>
Upvotes: 2
Views: 3913
Reputation: 1337
font-family.+?;
would match to 'font-family: fantasy;' in your case. You can just replace it with empty string. Your regex string makes no sense to me.
Perhaps this will help you understand what is wrong better than i can explain it https://regex101.com/
Looks like you're having some trouble understanding regex.
LE: your code should be.
if(isset($_POST["submit"]))
{
$editor = $_POST['editor'];
$editor = preg_replace('/font-family.+?;/', "", $editor);;
echo $editor;
}
Upvotes: 4