You are here: Re: What If Someone Uses My Delimiter In Their Comment? « All PHP « IT news, forums, messages
Re: What If Someone Uses My Delimiter In Their Comment?

Posted by NC on 09/28/83 11:47

Jacob.Lyles@gmail.com wrote:
>
> I'm making a comment form for my website that will store
> the results in a flat file with some sort of delimiting character.
> However, I'm wondering what will happen if someone uses
> my delimiter within their comment.

One way to get around it is to use enclosing characters in addition to
delimiting characters. For example, if you use comma-separated
variables (CSV) format, you can write:

"1","name","comment including a , (comma)"

instead of

1,name,comment including a , (comma)

This way, you can read your file with fgetcsv() without a problem.
Remember to escape double quotes with another double quote when writing
to file though...

> I thought one way to protect againt this would be to choose a
> character like < and convert all < to &lt . Is there a function in PHP
> that does this automatically?

Yes. Two, as a matter of fact:

http://www.php.net/htmlentities
http://www.php.net/htmlspecialchars

Cheers,
NC

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация