I m using hindi language to display data to user. but i want to replace a specific letter from all the words that appears to user. I want to replace
"ख" with "ष"
"खा" with "षा"
and respectively. I want to replace this at the time of inserting in database.
Means if user types "ख" in any form , it should be inserted as "ष" in database. So anybody has idea about this???
Asked
Active
Viewed 284 times
0

Kedar B
- 774
- 5
- 18
- 47
-
I don't know hindi and language construct but you can look in to php manual and try "str_replace" function – bart Mar 14 '14 at 10:47
-
[You may check this answer](http://stackoverflow.com/questions/3786003/str-replace-on-multibyte-strings-dangerous). – The Alpha Mar 14 '14 at 10:57
2 Answers
0
You can use mb_ereg_replace
<?php
$a='[ख]';
$string="खखखख Hello खखखखखख";
$b=mb_ereg_replace( $a, 'षा' , $string );
echo $b;
//output: षाषाषाषाषाषाषाषा Hello षाषाषाषाषाषाषाषाषाषाषाषा
?>
Make sure you set your html to utf-8
and include this at the start of your page:
define('CHARSET','UTF-8');
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');

Michel
- 4,076
- 4
- 34
- 52
0
I created my own library file called stringhandler.php. following is the stringhandler.php.
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class stringhandler {
function normalize_str($str)
{
$invalid = array('ख'=>'ष', 'खा'=>' षा', 'खि'=>'षि', 'खी'=>'षी', 'खु'=>'षु', 'खू'=>'षू',
'खे'=>'षे', 'खै'=>'षै', 'खो'=>'षो', 'खौ'=>' षौ', 'खं'=>' षं', 'खः'=>'षः');
$str = str_replace(array_keys($invalid), array_values($invalid), $str);
return $str;
}
}
And in model file
'fname'=>$this->stringhandler->normalize_str($this->input->post('fname')),
'fathername'=>$this->stringhandler->normalize_str($this->input->post('fathername')),
Hope this will help someone..

Kedar B
- 774
- 5
- 18
- 47