From: Rick Dwyer on
Hello List.

I'm trying to replace the registered (®) symbol from a variable via PHP.

The variable $mystring is set to a MySQL field that contains the value
"This Is The Registered Symbol ®".

Using the following, I try to replace the symbol, but it persists:

$moditem = str_replace("®","","$mystring");

I tried replacing the symbol in the above syntax with the HTML
equivalent but no luck.

Any help is appreciated.

Thanks,

--Rick


From: "Bob McConnell" on
From: Rick Dwyer

> I'm trying to replace the registered ((r)) symbol from a variable via
PHP.
>
> The variable $mystring is set to a MySQL field that contains the value

> "This Is The Registered Symbol (r)".
>
> Using the following, I try to replace the symbol, but it persists:
>
> $moditem = str_replace("(r)","","$mystring");
>
> I tried replacing the symbol in the above syntax with the HTML
> equivalent but no luck.

It depends on what you want it for. For a URL, the HTML encoding is
'®' '®' or '%AE'.

Bob McConnell
From: Daniel Brown on
On Fri, Jun 18, 2010 at 16:32, Rick Dwyer <rpdwyer(a)earthlink.net> wrote:
> Hello List.
>
> I'm trying to replace the registered (®) symbol from a variable via PHP..
>
> The variable $mystring is set to a MySQL field that contains the value "This
> Is The Registered Symbol ®".
>
> Using the following, I try to replace the symbol, but it persists:
>
> $moditem = str_replace("®","","$mystring");
>
> I tried replacing the symbol in the above syntax with the HTML equivalent
> but no luck.

Check your database's character encoding. My check:

<?php
$row = mysql_fetch_assoc(mysql_query("SELECT * FROM `example`"));

$mystring = $row['testfield'];

$moditem = str_replace("®","",$mystring);

echo $moditem.PHP_EOL;
?>

.... worked as expected. Note that, while it won't make a
difference in your result here, you don't need to use quotes around
your variable in the str_replace() call you showed. In fact, not only
would it slow down the processes on more-involved or more-popular
sites, but it'll have a larger impact, as you're using double quotes,
which are first evaluated, then passed. Single quotes would, of
course, literally echo $mystring in your case, but you get the point.
Just a quick tip.

--
URGENT:
THROUGH FRIDAY, 18 JUNE ONLY: $100 OFF
YOUR FIRST MONTH, FREE CPANEL FOR LIFE
ON ANY NEW DEDICATED SERVER. NO LIMIT!
</Daniel P. Brown>
daniel.brown(a)parasane.net || danbrown(a)php.net
http://www.parasane.net/ || http://www.pilotpig.net/
From: Rick Dwyer on

On Jun 18, 2010, at 4:52 PM, Daniel Brown wrote:
>>
>
> Check your database's character encoding. My check:


Navicat shows it as Latin1. I believe UTF-8 is what it should be, but
I don't want to change it without understanding what impact it will
have.

> Note that, while it won't make a
> difference in your result here, you don't need to use quotes around
> your variable in the str_replace() call you showed. In fact, not only
> would it slow down the processes on more-involved or more-popular
> sites, but it'll have a larger impact, as you're using double quotes,
> which are first evaluated, then passed. Single quotes would, of
> course, literally echo $mystring in your case, but you get the point.
> Just a quick tip.

Did not know, thanks.
From: Daniel Brown on
On Fri, Jun 18, 2010 at 17:07, Rick Dwyer <rpdwyer(a)earthlink.net> wrote:
>
> Navicat shows it as Latin1.  I believe UTF-8 is what it should be, but I
> don't want to change it without understanding what impact it will have.

Depending on your content, it could be an issue, but probably not.
A good way to check would be to copy the table, convert the encoding,
and test it. However, my example database with LATIN1 collation still
worked as expected here. So that may not be the issue for you after
all.

Can you hit the database from the command line to see if there's a
difference in the output when you take the server and browser out of
the equation?

--
</Daniel P. Brown>
URGENT:
THROUGH FRIDAY, 18 JUNE ONLY: $100 OFF
YOUR FIRST MONTH, FREE CPANEL FOR LIFE
ON ANY NEW DEDICATED SERVER. NO LIMIT!
daniel.brown(a)parasane.net || danbrown(a)php.net
http://www.parasane.net/ || http://www.pilotpig.net/
We now offer SAME-DAY SETUP on a new line of servers!