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('/<(\/?a(?:|\s[\S\s]+?))>/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.