Re: php, oracle and ascii characters
| From: | Steve Brett | Date: | Fri, 09 Nov 2001 10:05:20 +0000 |
| Subject: | Re: php, oracle and ascii characters | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-14175@lists.php.net to get a copy of this message | ||
Dan,
This sorts out your problem completely.
htmlentities() will encode the data as it is inserted into the database and
get_html_translation_table will help you translate it so it can be viewed in
the browser. Have a look at the manual page for the
get_html_translation_table function displayed below and you'll be sorted.
Steve
PHP Manual
Prev Next
----------------------------------------------------------------------------
----
get_html_translation_table
(PHP 4 >= 4.0b4)
get_html_translation_table -- Returns the translation table used by
htmlspecialchars() and htmlentities()
Description
string get_html_translation_table (int table [, int quote_style])
get_html_translation_table() will return the translation table that is used
internally for htmlspecialchars() and htmlentities(). There are two new
defines (HTML_ENTITIES, HTML_SPECIALCHARS) that allow you to specify the
table you want. And as in the htmlspecialchars() and htmlentities()
functions you can optionally specify the quote_style you are working with.
The default is ENT_COMPAT mode. See the description of these modes in
htmlspecialchars(). Example 1. Translation Table Example
$trans = get_html_translation_table (HTML_ENTITIES);
$str = "Hallo & <Frau> & Krämer";
$encoded = strtr ($str, $trans);
The $encoded variable will now contain: "Hallo & <Frau> &
Krämer".
The cool thing is using array_flip() to change the direction of the
translation.
$trans = array_flip ($trans);
$original = strtr ($str, $trans);
The content of $original would be: "Hallo & <Frau> & Krämer".
Note: This function was added in PHP 4.0.
See also: htmlspecialchars(), htmlentities(), strtr(), and array_flip().
----------------------------------------------------------------------------
----
Prev Home Next
explode Up get_meta_tags
"Dan Christie" <danchristie@earthlink.net> wrote in message
news:20011109034322.47021.qmail@pb1.pair.com...
> We are creating a content management system for a web site. In this app,I
am
> filling the contents of an html text area with the contents of a field in
an
> oracle database. This is our dynamic content for the site.The text area
> allows the user to update its contents. For the time being, any characters
> oracle considers illegal were to be entered by the client manually in
their
> ascii form. For instance, ' will be '. We thought this would be a
short
> term solution allowing the browser to see the characters correctly, and
the
> database to not error on the update.
> The content can be saved to the database correctly, but when it is
retrieved
> there seems to be a conversion going on. I am seeing the character
> interpreted as \' causing the next update on this field to fail. It is
> strange because when I view the source, the html correctly keeps the
',
> but when I use it in a php string and send it to the database, it seems to
> be making a switch.
> I need to keep this consistantly in its ascii representation, except when
it
> is viewed in a browser.
>
> Thanks, I'm desparate!
>
> Dan
>
>