ShadowMage Posted December 28, 2009 Share Posted December 28, 2009 Hi,I have a bit of a situation. I have some information in a database that needs to have a trademark symbol (™) when it displays in the browser. I tried copying the symbol from MS Word, but that didn't show up. So I decided to store raw html entities in the db (™) but that isn't a good solution either because it is possible for other symbols, like &, to be in there and storing raw entities for each and every possible symbol is ridiculous.So the solution I've implemented now is this:I store the information with something like this, ( TM ), where I want the symbol.When I retrieve the data, I use htmlentities() to convert all other symbols and then use str_replace() to replace the ( TM ) with ™**There are no spaces in the ( TM ) but I needed to put them in otherwise BB Code translated them to $data = htmlentities($recordset['DataField']);$newValue = str_replace("(TM)", "™", $data); Is there a better way to do this?Please advise.Thanks,jkloth Link to comment Share on other sites More sharing options...
justsomeguy Posted December 28, 2009 Share Posted December 28, 2009 Why exactly is storing ™ in the database a bad idea? Link to comment Share on other sites More sharing options...
ShadowMage Posted December 28, 2009 Author Share Posted December 28, 2009 Why exactly is storing ™ in the database a bad idea?Because there can be other symbols like & and " in there and I don't want to have to enter & and " in the database everytime I need a & or ". And if I have a mixture of ™ and & then using htmlentities won't work. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 28, 2009 Share Posted December 28, 2009 But if they submit an actual character, then you should be able to use htmlentities to convert that to ™ automatically, along with the other characters. You could also allow your special sequence instead of the character, and convert that manually. Link to comment Share on other sites More sharing options...
ShadowMage Posted December 28, 2009 Author Share Posted December 28, 2009 But if they submit an actual character, then you should be able to use htmlentities to convert that to ™ automatically, along with the other characters. You could also allow your special sequence instead of the character, and convert that manually.The table where this info is stored is manually entered data. The table stores different categories which are then used to populate a drop down list. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 28, 2009 Share Posted December 28, 2009 Ok. Link to comment Share on other sites More sharing options...
ShadowMage Posted December 28, 2009 Author Share Posted December 28, 2009 Ok.Ok what? ...My solution good enough? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 28, 2009 Share Posted December 28, 2009 If it works, then I guess it's good enough. I wasn't sure what the information in post 5 was for, the suggestion I had in post 4 doesn't matter what you use the data for. Link to comment Share on other sites More sharing options...
ShadowMage Posted December 28, 2009 Author Share Posted December 28, 2009 If it works, then I guess it's good enough. I wasn't sure what the information in post 5 was for, the suggestion I had in post 4 doesn't matter what you use the data for.Sorry, guess I should have explained myself a bit more. But if they submit an actual character, then you should be able to use htmlentities to convert that to ™ automatically, along with the other characters. You could also allow your special sequence instead of the character, and convert that manually.The table where this info is stored is manually entered data. The table stores different categories which are then used to populate a drop down list.What I meant here was that the data is not submitted from anywhere. It's manually entered into the MySQL Database through OpenOffice Base. So you're suggestion would not apply since there is no submitting going on. I am only reading from the table in my code.So what I wanted to know is if there was a better way to store the information. My solution works though so I guess I'll stick with it.Thanks, justsomeguy. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 29, 2009 Share Posted December 29, 2009 Ideally you would escape everything, you could put together a form to insert or even just to escape the data, where you would copy the escaped data and use that for the database. There's nothing really wrong with yours though. Link to comment Share on other sites More sharing options...
ShadowMage Posted December 29, 2009 Author Share Posted December 29, 2009 I was planning on building a database manager onto the project in the future so I could use that to add new data instead of interacting directly with the db. I'll have to keep your suggestions in mind when I get around to building the db manager.Thanks again, jsg Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.