Mudsaf Posted August 15, 2013 Share Posted August 15, 2013 Hello, i'm wondering how to striptags span element only allowing title attribute on it. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 15, 2013 Share Posted August 15, 2013 I'm not sure what you're asking, do you have an example? strip_tags doesn't do anything with attributes, only entire tags. Link to comment Share on other sites More sharing options...
Mudsaf Posted August 15, 2013 Author Share Posted August 15, 2013 (edited) Well if user enters tags example $MyString = '<span style="display:block;" title="WADAP">MyText</span>';strip_tags ($MyString,"<span title>"); //So this would remove the style attribute. Result should look like <span title="WADAP">MyText</span> Edited August 15, 2013 by Mudsaf Link to comment Share on other sites More sharing options...
justsomeguy Posted August 15, 2013 Share Posted August 15, 2013 strip_tags doesn't remove attributes, it removes tags. You'll need to use a regular expression if you want to remove attributes. Link to comment Share on other sites More sharing options...
Mudsaf Posted August 17, 2013 Author Share Posted August 17, 2013 I found tutorial for style, but didin't find method to remove ID and CLASS attributes. preg_replace('/style=(["'])[^1]*?1/i', '', $item, -1); Link to comment Share on other sites More sharing options...
justsomeguy Posted August 19, 2013 Share Posted August 19, 2013 I see several examples if I do a search. If this is user-generated HTML then it would be safer to load the HTML into a DOMDocument object and traverse through the nodes, where you can call removeAttribute to remove attributes for a node and then write out the final HTML. DOMDocument will behave better for broken HTML. http://docs.php.net/manual/en/domdocument.loadhtml.php Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now