Path: csiph.com!weretis.net!feeder4.news.weretis.net!news.mb-net.net!open-news-network.org!.POSTED.40.232.197.178.dynamic.wless.lssmb00p-cgnat.res.cust.swisscom.ch!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.php Subject: Re: Problems with accents Date: Thu, 17 May 2018 12:32:19 +0200 Organization: PointedEars Software (PES) Lines: 123 Message-ID: <2325308.HWs9MH8kAM@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit Injection-Info: gwaiyur.mb-net.net; posting-host="40.232.197.178.dynamic.wless.lssmb00p-cgnat.res.cust.swisscom.ch:178.197.232.40"; logging-data="5641"; mail-complaints-to="abuse@open-news-network.org" User-Agent: KNode/4.14.2 Cancel-Lock: sha1:Uu5vr2XQTL00f+gJXtjvO0QQvTc= X-User-ID: U2FsdGVkX18TQZbdFIkNEZz1ld2A0ADXMQRqBDqoAr51LOXvXAlJUQ== Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. This is working well: > print "L'homme\n"; > Buts this > print "

INPUT NAME='titre' VALUE='l\'homme'>\n"; > Print only upto the appostrophe! : l\ > Any idea?? As you can see if you look at the source code of the dynamically generated Web document (e.g. with Ctrl+U), this generates some sort of HTML markup:

INPUT NAME='titre' VALUE='l\'homme'> (without indentation). But HTML is _not_ PHP; if, as you intended, you use the apostrophe as (“VALUE”) attribute value delimiter, then for a literal apostrophe you have to escape it with a character reference:

INPUT NAME='titre' VALUE='l'homme'> This can be automated with PHP: echo "

INPUT NAME='titre' VALUE='l" . htmlspecialchars("'", ENT_QUOTES) . "homme'>"; (Do not use “print” unless you are interested in the return value. ) In fact, if the attribute value is from a PHP value, the whole attribute value should be escaped: echo "

INPUT NAME='titre' VALUE='" . htmlspecialchars($value, ENT_QUOTES) . ">"; But if the value is fixed, in this special case it is easier, and usually better, to use another delimiter both for the PHP string and the HTML attribute value: echo '

INPUT NAME="titre" VALUE="l'homme">'; The problem does not arise in the first place if you use the *proper* (typographical) apostrophe:

INPUT NAME='titre' VALUE='l’homme'> Also, your markup is syntactically wrong; a leading “<” character is missing for the “input” element:

This is still *semantically* wrong, because an “input” element does not belong in a paragraph (“p”) element; but, for example, in a “fieldset” element:

Assuming that “l’homme” is an attribute value that is not fixed, but comes from a PHP value, then it is not necessary to use either “echo” or “print”; PHP is the *P*HP *H*ypertext *P*reprocessor: $value = 'l’homme'; ?>
This approach also works better with syntax highlighting. You should avoid language-specific identifiers and values that are not displayed to the user. Your code will be easier to write, and easier understood by others, if you choose identifiers in English, the /lingua franca/ of computer technology. For example, in this case a “select” element is usually the proper element, where the “option” elements’ values should be in English, and the element’s content can be in the user’s language (which can be automated with classes such as Zend\I18n\Translator\Translator): If this is part of a form, it would be better to use a table anyway, where the table headers contain the labels and the table data are the form controls:
User data
Titre
Such *HTML* basics are usually discussed in only. Finally, an apostrophe is _not_ an accent; both are diacritic marks. -- PointedEars Zend Certified PHP Engineer | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.