Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17747

Re: Problems with accents

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.php
Subject Re: Problems with accents
Date 2018-05-17 12:32 +0200
Organization PointedEars Software (PES)
Message-ID <2325308.HWs9MH8kAM@PointedEars.de> (permalink)
References <pdjctl$m7g$1@gioia.aioe.org>

Show all headers | View raw


andre wrote:
^^^^^
Your last name is missing there, André no. 74656.

> This is working well:
> print "L'homme\n";
> Buts this
> print "<P>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:

  <P>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:

  <P>INPUT NAME='titre' VALUE='l&#39;homme'>

This can be automated with PHP:

  echo "<P>INPUT NAME='titre' VALUE='l" . htmlspecialchars("'", ENT_QUOTES) 
. "homme'>";

<https://php.net/htmlspecialchars>

(Do not use “print” unless you are interested in the return value.  
<https://php.net/print>)

In fact, if the attribute value is from a PHP value, the whole attribute 
value should be escaped:

  echo "<P>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 '<P>INPUT NAME="titre" VALUE="l'homme">';

The problem does not arise in the first place if you use the *proper* 
(typographical) apostrophe:

  <P>INPUT NAME='titre' VALUE='l’homme'>


Also, your markup is syntactically wrong; a leading “<” character is missing 
for the “input” element:

  <P><input name="titre" value="l’homme">

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

  <fieldset><input name="titre" value="l’homme"> …</fieldset>

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';

  ?><fieldset><input name="titre" value="<?= htmlspecialchars($value) ?>"> …
</fieldset>

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):

  <select name="title" size="1">
    <option value="Mr.">M.</option>
    <option value="Ms.">Mme</option>
    <option value="Dr.">Dr</option>
    <option value="Prof.">Pr</option>
  </select>


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:

  <fieldset>
    <legend>User data</legend>
    <table>
      <tr>
        <th>Titre</th>
        <td><select name="title" size="1">
          <option value="Mr.">M.</option>
          <option value="Ms.">Mme</option>
          <option value="Dr.">Dr</option>
          <option value="Prof.">Pr</option>
        </select></td>
      </tr>
      …
    </table>
  </fieldset>

Such *HTML* basics are usually discussed in 
<news:comp.infosystems.www.authoring.html> only.


Finally, an apostrophe is _not_ an accent; both are diacritic marks.

-- 
PointedEars
Zend Certified PHP Engineer <http://www.zend.com/en/yellow-pages/ZEND024953>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Problems with accents andre <ahr@blabla.be> - 2018-05-17 10:01 +0200
  Re: Problems with accents Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-05-17 12:32 +0200
    Re: Problems with accents andre <pasmoi@pasici.be> - 2018-05-17 13:36 +0200
      Re: Problems with accents Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-05-17 14:31 +0200
        Re: Problems with accents Jerry Stuckle <jstucklex@attglobal.net> - 2018-05-18 08:50 -0400
      Re: Problems with accents Jerry Stuckle <jstucklex@attglobal.net> - 2018-05-18 08:55 -0400
    Re: Problems with accents Jerry Stuckle <jstucklex@attglobal.net> - 2018-05-18 08:47 -0400
  Re: Problems with accents Richard Yates <richard@yatesguitar.com> - 2018-05-17 05:58 -0700
  Re: solved: Problems with accents andre <pasmoi@pasici.be> - 2018-05-18 17:13 +0200
    Re: solved: Problems with accents Jerry Stuckle <jstucklex@attglobal.net> - 2018-05-18 13:36 -0400
      Re: solved: Problems with accents andre <pasmoi@pasici.be> - 2018-05-19 10:09 +0200
        Re: solved: Problems with accents Jerry Stuckle <jstucklex@attglobal.net> - 2018-05-19 08:48 -0400
        Re: solved: Problems with accents Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-05-19 20:18 +0200
          Re: solved: Problems with accents Jerry Stuckle <jstucklex@attglobal.net> - 2018-05-19 18:33 -0400
            Re: solved: Problems with accents "Peter H. Coffin" <hellsop@ninehells.com> - 2018-05-20 10:44 -0500

csiph-web