Connecting Tech Pros Worldwide Forums | Help | Site Map

Quotes from Db into textfield

frizzle
Guest
 
Posts: n/a
#1: Mar 1 '06
Hi there,

i have a problem of wich i doubt it can be solved properly:
If i call a text from a (mySQL) database, and want to echo it into a
textfield (e.g. in a form) i experience the following problem (wich
makes sense, but wich i can't solve):

Imagine the following:[color=blue][color=green]
>> $db_string = 'The speech started as following: "Ladies and Gentlemen!".';[/color][/color]

Source php:[color=blue][color=green]
>> <input name="textfield" type="text" value="<?php echo $db_string; ?>">[/color][/color]

Source html:[color=blue][color=green]
>> <input name="textfield" type="text" value="The speech started as following: "Ladies and Gentlemen!".">[/color][/color]

Wich only displays on the site:[color=blue][color=green]
>> The speech started as following:[/color][/color]

Makes sense to me, but i cannot figure out how to solve it ...
(escaping with \" makes the backslash the last char)

Frizzle.


Michael Fesser
Guest
 
Posts: n/a
#2: Mar 1 '06

re: Quotes from Db into textfield


..oO(frizzle)
[color=blue]
>i have a problem of wich i doubt it can be solved properly:
>If i call a text from a (mySQL) database, and want to echo it into a
>textfield (e.g. in a form) i experience the following problem (wich
>makes sense, but wich i can't solve):[/color]

www.php.net/htmlspecialchars

Micha
frizzle
Guest
 
Posts: n/a
#3: Mar 2 '06

re: Quotes from Db into textfield


Michael Fesser wrote:[color=blue]
> .oO(frizzle)
>[color=green]
> >i have a problem of wich i doubt it can be solved properly:
> >If i call a text from a (mySQL) database, and want to echo it into a
> >textfield (e.g. in a form) i experience the following problem (wich
> >makes sense, but wich i can't solve):[/color]
>
> www.php.net/htmlspecialchars
>
> Micha[/color]

OK, i get what you mean, but i had already thought of that, but kind of
immediately faced the following problem: What if someone writes a
HTML-tutorial, and uses

&quot;

as a text, or even

"&quot;"

which would become

"""

So i believe this isn't the solution yet ... ( ? )

Frizzle.

Michael Fesser
Guest
 
Posts: n/a
#4: Mar 2 '06

re: Quotes from Db into textfield


..oO(frizzle)
[color=blue]
>OK, i get what you mean, but i had already thought of that, but kind of
>immediately faced the following problem: What if someone writes a
>HTML-tutorial, and uses
>
>&quot;
>
>as a text, or even[/color]

This would become

&amp;quot;
[color=blue]
>"&quot;"
>
>which would become
>
>"""[/color]

It would become

&quot;&amp;quot;&quot;

Micha
frizzle
Guest
 
Posts: n/a
#5: Mar 5 '06

re: Quotes from Db into textfield



Michael Fesser wrote:[color=blue]
> .oO(frizzle)
>[color=green]
> >OK, i get what you mean, but i had already thought of that, but kind of
> >immediately faced the following problem: What if someone writes a
> >HTML-tutorial, and uses
> >
> >&quot;
> >
> >as a text, or even[/color]
>
> This would become
>
> &amp;quot;
>[color=green]
> >"&quot;"
> >
> >which would become
> >
> >"""[/color]
>
> It would become
>
> &quot;&amp;quot;&quot;
>
> Micha[/color]

Ok, i get this, but if i call the text from the DB and put it into a
field:
from the db (raw) : "
into html textfield : ... value="&quot;" ...

It should display correctly, but what i meant, if a person types
another
quote into the field, so both are original quotes, things get messed
up,
because there is a html quote in it, and a real one.

I could use html_entities_decode, but this would also mess up the html-
tutorial characters ...

Frizzle.

Closed Thread


Similar PHP bytes