Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Hala's avatar
Level 3

HTMLPurifier allow target blank

i have purifier config having this

'HTML.Allowed' => 'a[href|rel|target]',

when i make

Purify::clean($body);

the body return without target='_blank'

0 likes
7 replies
Hala's avatar
Level 3

I checked them before did not work only target work if i added 'HTML.TargetBlank'=>true,

Hala's avatar
Level 3

Thank you, but i need to stick with the package i used

MichalOravec's avatar

It's up to you, I recommend change your app to that package, for future.

1 like
coxy121's avatar
coxy121
Best Answer
Level 20

I was able to achieve this by using the following

$config = [
	'HTML.Allowed' => 'a[href|target]',
	'Attr.AllowedFrameTargets' => ['_blank']
];
Purify::clean($value, $config);

This then returned

<a href="..." target="_blank">...</a>
Hala's avatar
Level 3

Hello @coxy121 , it was from 2 months ago , and i found what you did do

Thank you so much

1 like

Please or to participate in this conversation.