我有一个动态菜单,我需要使用CSS类转换为背景图像.我想将标签转换为css的安全类名.
一个例子是: - 转换字符串:'Products&Sunflowers' - 转换为仅包含az和1-9的字符串.以上内容将转换为可用作类名的验证字符串,例如:'products_sunflowers'
tsi*_*tsi 19
我用这个:
preg_replace('/\W+/','',strtolower(strip_tags($className)));
Run Code Online (Sandbox Code Playgroud)
它将除去所有字母,转换为小写并删除所有html标记.