0

राम (hindi language)

I am working on a table where many rows contains value like this राम it shows in browser like राम and many rows already contains राम but I want to replace all encoded value with decode values for this i used find replace query also put data in form and updated but every time db stores encoded value

Structure of table

hindi   varchar(256)    utf8_unicode_ci

what i did

<?php
echo $queryfetch="select hindi from users where id='2'";
$resultfetch=mysqli_query($c,$queryfetch);
while($row  =   mysqli_fetch_array($resultfetch))
{
echo $queryupdate="update users set hindi='".html_entity_decode($row['hindi'])."' where id='2'";
$resultupdate=mysqli_query($c,$queryupdate);
}
?>
select hindi from users where id='2'

update users set hindi='राम' where id='2'

**
sql before =&#2352;&#2366;&#2350;

**sql after = राम**
prameshwer
  • 121
  • 16
  • 4
    encrypted != encoded – Blue Oct 03 '18 at 10:18
  • And out of interest in your find replace query what did you replace the encoded characters with? – RiggsFolly Oct 03 '18 at 10:21
  • @RiggsFolly ok i updated my question – prameshwer Oct 03 '18 at 10:22
  • @Riggs Those are *HTML entities*. You can't talk about UTF-8 encoding without looking at the bytes, which we are not here. – deceze Oct 03 '18 at 10:44
  • @deceze In my defence, the question has changed a bit since I last looked at it – RiggsFolly Oct 03 '18 at 10:46
  • @prameshwer Looks like you're decoding your HTML entities, but are then failing to handle UTF-8 correctly to/from the database/browser. See the duplicate. – deceze Oct 03 '18 at 10:46
  • @deceze Is there any way in sql to decode all html entities without using any form ? because i am trying to do this from 2 days and i have more that 15,000 rows – prameshwer Oct 03 '18 at 10:49
  • If for whatever reason you can't convert all the data in one go, you can simply do it "in production": add some sort of flag (column) to note whether a row has been converted or not. Whenever you get data from the database, convert it or not based on that flag. Whenever you *update* the data anyway, do it correctly and then unflag that row. Eventually all your data should be in a sane state. Hopefully your data access layer is sufficiently centralised so you just have to implement this change in very few places… – deceze Oct 03 '18 at 10:54

1 Answers1

0

What you have are html-encoded characters. To decode them, you need:

html_entity_decode('&#2352;&#2366;&#2350;')

An example.

jeroen
  • 91,079
  • 21
  • 114
  • 132