Re: How do I display apostrophe in PHP generated form?
| From: | Glash Gnome | Date: | Sun, 28 Nov 2021 21:47:06 +0000 |
| Subject: | Re: How do I display apostrophe in PHP generated form? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-327834@lists.php.net to get a copy of this message | ||
Hello,
Maybe htmlentities =>
https://www.php.net/manual/fr/function.htmlentities.php
Le dim. 28 nov. 2021 à 22:35, John <john.iliffe@iliffe.ca> a écrit :
> I have an application where the user enters a name which is
> subsequently passed to another PHP script for validation using JSON.
> If the user's name is, eg O'Toole, then the initial PHP script accepts
> it correctly, the JSON format passes it correctly and if I just do a
> display of the received JSON block it is correct, but when I put it
> into the <input> element of a form for validation everything to the
> right of the ' gets dropped.
>
> I have tried addslashes() and that results in: 'O'Toole' --> 'O\'
>
> The specific lines of code:
>
> -------
>
> echo $addrdec['address']['city']; <-- result of associative array
> recovered correctly from JSON coding
>
> results in "St John's"
>
> -------
>
> echo "<input type=text name=rcity id=rcity length=32 size=20 value='"
> . addslashes($addrdec['address']['city']) . "'></input>
>  ";
>
> results in display "St John\"
>
> Looking at the page source that resulted from this the value part of
> the element (Firefox won't let me copy it directly):
>
> .... size="20" value="St John\" s'="">
>
>
> -------
>
> and if I don't use addslashes the value becomes 'St John', truncating
> the 's' following the apostrophe. Frankly, I would have expected a
> syntax error if the ' were being used to close the literal but that
> doesn't happen.
>
> Looking at the page source that resulted from this the value part of
> the element (Firefox won't let me copy it directly):
>
> .... size="20" value="St John\" s'="">
>
> How can I resolve this?
>
> Thanks in advance.
>
> John
> ============
>