Re: Replacing Registered Symbol
| From: | Daniel Brown | Date: | Fri, 18 Jun 2010 20:52:09 +0000 |
| Subject: | Re: Replacing Registered Symbol | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-306255@lists.php.net to get a copy of this message | ||
On Fri, Jun 18, 2010 at 16:32, Rick Dwyer <rpdwyer@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@parasane.net || danbrown@php.net
http://www.parasane.net/ || http://www.pilotpig.net/