Jump to content

Storing information in attributes


Shadowing

Recommended Posts

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

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']) . '" />';

  • Like 1
Link to comment
Share on other sites

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

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 by Shadowing
Link to comment
Share on other sites

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 by Shadowing
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...