简体   繁体   中英

Disable all tags except for <a>

I want to encode ( htmlentities ) or disable all tags except for <a> tags.

How can I achieve this?

After using HTML entities, convert the links back using a RegExp:

preg_replace('/&lt;(\/?a(?:|\s[\S\s]+?))&gt;/i', '<$1>', $string);

If you want other tags to be removed, use:

strip_tags($string, '<a>');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM