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