Invert search reason

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
flyguille
New php-forum User
New php-forum User
Posts: 8
Joined: Thu Nov 29, 2018 1:53 pm

Sun Dec 30, 2018 9:26 am

hi guys, I am bit new on PHP programming.

I grab this code:


$strip_tags = "a|strong|em|iframe";
$Clean = preg_replace('#<\s*\/?(' . $strip_tags . ')\s*[^>]*?>#im', '', $_POST['Bio']);

I need to invert, it, like

$allow_tags = "br|p|div|b";
$Clean = preg_replace('#<\s*\/?(' . $allow_tags . ')\s*[^>]*?>#im', '', $_POST['Bio']);

I tried to insert the ^ simbol in the pattern, but it returns empty string. Where to place the ^?

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 792
Joined: Mon Feb 22, 2016 5:52 pm

Sun Dec 30, 2018 10:55 am

I'm not sure why you would need to preserve tags in a preg_replace statement, it doesn't make any sense since you can ignore them and they will stay?

Have a look at the built in strip_tags function

flyguille
New php-forum User
New php-forum User
Posts: 8
Joined: Thu Nov 29, 2018 1:53 pm

Sun Dec 30, 2018 1:21 pm

instead of specifying a large list of tag that I wan't.

I want to specify only the few 3 or 4 HTML tags that it will allow.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 792
Joined: Mon Feb 22, 2016 5:52 pm

Mon Dec 31, 2018 11:08 am

instead of specifying a large list of tag that I wan't.
strip_tags is still your friend.

Post Reply