Shadowing Posted June 10, 2012 Share Posted June 10, 2012 Hey guys what is the best way to store information in a attribute I notice i cant store ' in attributes. or is there something i can do so i can? i was trying to use data Link to comment Share on other sites More sharing options...
eTianbun Posted June 10, 2012 Share Posted June 10, 2012 I dont get you, is it that you want apostrophe (') to be among the value of attribute? (') = ' Link to comment Share on other sites More sharing options...
Shadowing Posted June 10, 2012 Author Share Posted June 10, 2012 Hey CodeName yah thats what i mean. i want to beabel to store stuff like Don't you know that isn't fair. im using attributest to store a huge amount of data for when peopel hit reply in my forum but i didnt realize people cant use 'i realize today cause i tried to use it for something else and realize this. data='".($_POST['topic_page'])."' Link to comment Share on other sites More sharing options...
boen_robot Posted June 10, 2012 Share Posted June 10, 2012 Right, and as CodeName said (rather cryptically), you can store an apostrophe in an attribute by replacing it with ' or (for the sake of portability... long story...) ' Alternatively, if your attributes use double quotes, you can have double quotes inside the attribute by replacing them with " In PHP, you have a convinient function for that called htmlspecialchars(), and you can use it like for example: echo '<input name="topic_page" value="' . htmlspecialchars($_POST['topic_page']) . '" />'; 1 Link to comment Share on other sites More sharing options...
niche Posted June 10, 2012 Share Posted June 10, 2012 I store info all the time in attributes. I boen robot's last post is particularly informative. Thanks . Link to comment Share on other sites More sharing options...
Shadowing Posted June 10, 2012 Author Share Posted June 10, 2012 ahh i never really knew what htmlspecial characters really did until now lol , Thanks alot guys. for some reason when I saw Codename's reply i didnt notice the code example lol. I was like so tired thanks again guys Link to comment Share on other sites More sharing options...
Shadowing Posted June 10, 2012 Author Share Posted June 10, 2012 (edited) wierd i just tried this and its not working hmmif i store can'###### comes out as can $return = "<a href='' data='".htmlspecialchars($subject)."'>$subject</a>"; I'm storing it in data then grabing it with attr with jquery and then sending it back to a php page usingjquery ajax on the data field. Edited June 10, 2012 by Shadowing Link to comment Share on other sites More sharing options...
Shadowing Posted June 10, 2012 Author Share Posted June 10, 2012 (edited) oh htmlspecialchars isnt working cause im not using double quotes on the out side on the value of the attr so after doing some reading about htmlspecialchars apparently there is a 2nd parameter lol to escape the both quotes data='".htmlspecialchars($subject,ENT_QUOTES)."' Edited June 10, 2012 by Shadowing Link to comment Share on other sites More sharing options...
Ingolme Posted June 10, 2012 Share Posted June 10, 2012 It should work with both double-quotes and single-quotes. To encode single-quotes, pass the ENT_QUOTES parameter: htmlspecialchars("string", ENT_HTML401|ENT_QUOTES); 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