Re: How do I display apostrophe in PHP generated form?

[email protected] (John)
Newsgroups php.general
Message-ID <[email protected]>
First, thank you for the very prompt reply; your solution works.

I have always found this list to be very helpful and friendly and you
have continued the tradition. 

But, I don't completely understand why this was necessary.  To me, it
looks like a simple PHP echo command so why would I need to escape it
at this point.  There was a problem earlier in this project with data
passed by JSON and I had to use htmlspecialchars() to relay the JSON
data to the next script but that was the reverse of what I am doing
here.  I had seen htmlentities() (and htmlspecialchars() which is
noted as equivalent in the documentation) in my research but it didn't
seem appropriate because I was considering this as an echo function.

What am I failing to see?

Regards, and thanks again.

John
=============


On Sun, 2021-11-28 at 22:47 +0100, Glash Gnome wrote:
> Hello,
> 
> Maybe htmlentities =>
> https://www.php.net/manual/fr/function.htmlentities.php
> 
> 
> 
> Le dim. 28 nov. 2021 à 22:35, John <[email protected]> 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.
> > 
> > 
> > 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> &emsp;"; 
> > 
> > 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
> > ============
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.