htmlentities and single quote

What would be the best advice for storing HTML data in to a MySQL database?

I've tried using 'htmlspecialcharacters' and 'htmlentities' for converting
before storing in to db, but when converting back, am always having issues
displaying the single quote properly ( ' )

I want to be able to save HTML tags & content in to db. Using 'TEXT' as
field type.

Am able to save, retrieve and display back to browser, but am having
difficulties w/ the single ' quote issue
StreetGifts [ Fr, 12 Januar 2007 16:59 ] [ ID #1593563 ]

Re: htmlentities and single quote

StreetGifts wrote:
> What would be the best advice for storing HTML data in to a MySQL database?
>
> I've tried using 'htmlspecialcharacters' and 'htmlentities' for converting
> before storing in to db, but when converting back, am always having issues
> displaying the single quote properly ( ' )
>
> I want to be able to save HTML tags & content in to db. Using 'TEXT' as
> field type.
>
> Am able to save, retrieve and display back to browser, but am having
> difficulties w/ the single ' quote issue

This is not a solve for your problem, but I would advice you to use double
quotes in html tags, even if single quotes are valid, there are browsers that
don't handle single quotes properly, but the same tags with double quotes
works fine.

--

//Aho
Shion [ Fr, 12 Januar 2007 17:18 ] [ ID #1593565 ]

Re: htmlentities and single quote

StreetGifts wrote:
> What would be the best advice for storing HTML data in to a MySQL
> database?

As HTML data, unedited.
Just use mysql_real_escape_string() on it before putting it in the INSERT
query.
--
Rik Wasmus
Rik [ Fr, 12 Januar 2007 17:25 ] [ ID #1593566 ]

Re: htmlentities and single quote

Message-ID: <10d86$45a7b5e7$8259c69c$16834 [at] news1.tudelft.nl> from Rik
contained the following:

>> What would be the best advice for storing HTML data in to a MySQL
>> database?
>
>As HTML data, unedited.
>Just use mysql_real_escape_string() on it before putting it in the INSERT
>query.

I had a devil of a job recently trying to store an html file that had
loads of auto generated JavaScript in it (a crossword puzzle). My
quick and dirty solution was to save it as a file and then simply store
a reference to it. This is fine if you don't want to do any data
processing on the content.

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Geoff Berrow [ Fr, 12 Januar 2007 17:27 ] [ ID #1593567 ]

Re: htmlentities and single quote

Thanks ... issue I have is users are submitting HTML code with text and
simple words like "can't", "won't" and similar words are problematic -
thanks

"J.O. Aho" <user [at] example.net> wrote in message
news:50pqn8F1gllqfU1 [at] mid.individual.net...
> StreetGifts wrote:
>> What would be the best advice for storing HTML data in to a MySQL
>> database?
>>
>> I've tried using 'htmlspecialcharacters' and 'htmlentities' for
>> converting before storing in to db, but when converting back, am always
>> having issues displaying the single quote properly ( ' )
>>
>> I want to be able to save HTML tags & content in to db. Using 'TEXT' as
>> field type.
>>
>> Am able to save, retrieve and display back to browser, but am having
>> difficulties w/ the single ' quote issue
>
> This is not a solve for your problem, but I would advice you to use double
> quotes in html tags, even if single quotes are valid, there are browsers
> that don't handle single quotes properly, but the same tags with double
> quotes works fine.
>
> --
>
> //Aho
StreetGifts [ Fr, 12 Januar 2007 17:30 ] [ ID #1593568 ]

Re: htmlentities and single quote

Geoff Berrow wrote:
> Message-ID: <10d86$45a7b5e7$8259c69c$16834 [at] news1.tudelft.nl> from Rik
> contained the following:
>
>>> What would be the best advice for storing HTML data in to a MySQL
>>> database?
>>
>> As HTML data, unedited.
>> Just use mysql_real_escape_string() on it before putting it in the
>> INSERT query.
>
> I had a devil of a job recently trying to store an html file that had
> loads of auto generated JavaScript in it (a crossword puzzle). My
> quick and dirty solution was to save it as a file and then simply
> store
> a reference to it. This is fine if you don't want to do any data
> processing on the content.

If there are reasonably few html snippets/pages it could be OK. Wouldn't
want to try it with 1000+ files though, the filesystem becomes a
bottleneck.

Then again, just simply throwing it though mysql_real_escape_string()
_should_ have done the job without any hassle.
--
Rik Wasmus
Rik [ Fr, 12 Januar 2007 18:05 ] [ ID #1593570 ]

Re: htmlentities and single quote

Message-ID: <378bb$45a7bf44$8259c69c$19192 [at] news1.tudelft.nl> from Rik
contained the following:

>> I had a devil of a job recently trying to store an html file that had
>> loads of auto generated JavaScript in it (a crossword puzzle). My
>> quick and dirty solution was to save it as a file and then simply
>> store
>> a reference to it. This is fine if you don't want to do any data
>> processing on the content.
>
>If there are reasonably few html snippets/pages it could be OK. Wouldn't
>want to try it with 1000+ files though, the filesystem becomes a
>bottleneck.

I couldn't say. I always thought that's what the filesystem was good
at.
>
>Then again, just simply throwing it though mysql_real_escape_string()
>_should_ have done the job without any hassle.

Yeah, that's what I did. But after a couple of hours messing about with
it (and a tight budget) you do what you have to do.

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Geoff Berrow [ Fr, 12 Januar 2007 18:49 ] [ ID #1593571 ]

Re: htmlentities and single quote

Geoff Berrow wrote:
> Message-ID: <378bb$45a7bf44$8259c69c$19192 [at] news1.tudelft.nl> from Rik
> contained the following:
>
>>> I had a devil of a job recently trying to store an html file that
>>> had loads of auto generated JavaScript in it (a crossword puzzle).
>>> My quick and dirty solution was to save it as a file and then simply
>>> store
>>> a reference to it. This is fine if you don't want to do any data
>>> processing on the content.
>>
>> If there are reasonably few html snippets/pages it could be OK.
>> Wouldn't want to try it with 1000+ files though, the filesystem
>> becomes a bottleneck.
>
> I couldn't say. I always thought that's what the filesystem was good
> at.

Well, it's not really designed to hold 1000+ files in one directory. Split
them up in subdirs (for instance on first character) and it'll be much
faster again.

>> Then again, just simply throwing it though mysql_real_escape_string()
>> _should_ have done the job without any hassle.
>
> Yeah, that's what I did. But after a couple of hours messing about
> with it (and a tight budget) you do what you have to do.


Indeed, no use wasting hours on it offcourse. Allthough I'm interested in
what kind of gibberish was causing you this headache.
--
Rik Wasmus
Rik [ Fr, 12 Januar 2007 19:01 ] [ ID #1593572 ]

Re: htmlentities and single quote

Geoff Berrow wrote:
> Message-ID: <378bb$45a7bf44$8259c69c$19192 [at] news1.tudelft.nl> from Rik
> contained the following:
>
>>> I had a devil of a job recently trying to store an html file that had
>>> loads of auto generated JavaScript in it (a crossword puzzle). My
>>> quick and dirty solution was to save it as a file and then simply
>>> store
>>> a reference to it. This is fine if you don't want to do any data
>>> processing on the content.
>> If there are reasonably few html snippets/pages it could be OK. Wouldn't
>> want to try it with 1000+ files though, the filesystem becomes a
>> bottleneck.
> I couldn't say. I always thought that's what the filesystem was good
> at.

Much depends on what file system you are using, some are good at many small
files, others good at a few large ones, you should always choose file system
based on what you are going to do, XFS is great if you want speed, but not
that good if you machine has little ram or may be instable (running
experimental software). ZFS and Reiser4 are two upcoming good file systems,
which both offers features that other file systems don't.



--

//Aho
Shion [ Fr, 12 Januar 2007 18:59 ] [ ID #1593573 ]

Re: htmlentities and single quote

Message-ID: <5301a$45a7cc63$8259c69c$22256 [at] news1.tudelft.nl> from Rik
contained the following:

>Indeed, no use wasting hours on it offcourse. Allthough I'm interested in
>what kind of gibberish was causing you this headache.

It was the output from Eclipse Crossword. A client wanted to be able to
create and upload crosswords, so I wrote a function to strip out the
stuff I didn't want and saved the result in the db. Only it screwed
the JS



--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Geoff Berrow [ Fr, 12 Januar 2007 19:14 ] [ ID #1593574 ]

Re: htmlentities and single quote

Rik wrote:
> Geoff Berrow wrote:
>> Message-ID: <378bb$45a7bf44$8259c69c$19192 [at] news1.tudelft.nl> from Rik
>> contained the following:
>>
>>>> I had a devil of a job recently trying to store an html file that
>>>> had loads of auto generated JavaScript in it (a crossword puzzle).
>>>> My quick and dirty solution was to save it as a file and then simply
>>>> store
>>>> a reference to it. This is fine if you don't want to do any data
>>>> processing on the content.
>>> If there are reasonably few html snippets/pages it could be OK.
>>> Wouldn't want to try it with 1000+ files though, the filesystem
>>> becomes a bottleneck.
>> I couldn't say. I always thought that's what the filesystem was good
>> at.
>
> Well, it's not really designed to hold 1000+ files in one directory. Split
> them up in subdirs (for instance on first character) and it'll be much
> faster again.
>
>>> Then again, just simply throwing it though mysql_real_escape_string()
>>> _should_ have done the job without any hassle.
>> Yeah, that's what I did. But after a couple of hours messing about
>> with it (and a tight budget) you do what you have to do.
>
>
> Indeed, no use wasting hours on it offcourse. Allthough I'm interested in
> what kind of gibberish was causing you this headache.

1000 files are nothing, finding 10000 files takes not more than 0.02 - 0.04
seconds on a good file system, but of course if using something like fat-file
system, then things will be painful slow.


--

//Aho
Shion [ Fr, 12 Januar 2007 19:15 ] [ ID #1593575 ]

Re: htmlentities and single quote

J.O. Aho wrote:
> Rik wrote:
>> Geoff Berrow wrote:
>>> Message-ID: <378bb$45a7bf44$8259c69c$19192 [at] news1.tudelft.nl> from
>>> Rik contained the following:
>>>> If there are reasonably few html snippets/pages it could be OK.
>>>> Wouldn't want to try it with 1000+ files though, the filesystem
>>>> becomes a bottleneck.
>>> I couldn't say. I always thought that's what the filesystem was
>>> good
>>> at.
>>
>> Well, it's not really designed to hold 1000+ files in one directory.
>> Split them up in subdirs (for instance on first character) and it'll
>> be much faster again.
>
> 1000 files are nothing, finding 10000 files takes not more than 0.02
> - 0.04 seconds on a good file system, but of course if using
> something like fat-file system, then things will be painful slow.

I have to admit I'm not that into filesystems, I can only say I've
witnessed it first hand on a FreeBSD server, where splitting the directory
in subdirectories containing up to about 500-800 files increased
performance considerably.

Using fat on a server is just asking for it offcourse, not to mention
highly difficult to maintain security.
--
Rik Wasmus
Rik [ Fr, 12 Januar 2007 19:26 ] [ ID #1593577 ]
PHP » alt.php » htmlentities and single quote

Vorheriges Thema: Soap Fault
Nächstes Thema: Att: J.O Aho