I have some string like "।।ॐम्।।"
and I want to remove "।"
from the String using either JavaScript or PHP. The string in UTF8 format.
I had tried something like
$str="।।ॐम्।।";
alert($str.replace(/।/g,''));
but । is not removing,output is same as input.In PHP I tried with str_replace()
but no use.
Is there any way to do this?
<?php
header('Content-Type: text/html; charset=utf-8');
$str=$_POST['arg'];
$r=explode(" ",$str);
echo "Before Replace --> ".$r[6]."<br/>";
$str1="।।ॐम्।।";
$str1 = str_replace('।','',$str1);
$str2 = str_replace('।','',$r[6]);
echo "After Replace --><br/><br/> str1: ".$str1." <br/>str2: ".$str2;
?>
Not working. See the Output. enter image description here
Before Replace --> ।।ॐम्।।अथषड्विंशतिसूत्रप्रारंभः।।हरिःॐम्।।इ
After Replace -->
str1: ॐम्
str2: ।।ॐम्।।अथषड्विंशतिसूत्रप्रारंभः।।हरिःॐम्।।इ
Just use a simple trim()
, if you're only expecting same character on both ends.
<?php
$string = '।।ॐम्।।';
echo trim($string,'।'); //ॐम्
Use this code for javascript
var str="।।ॐम्।।";
alert(str.replace(/।/g,''));
Use this code for PHP
<?php
$str="।।ॐम्।।";
$str = trim(str_replace("।","",$str));
echo $str;
?>
This works...
"।।ॐम्।।".replace(/[।]/g, "");
output ॐम्
Be careful ! '।' isn't a pipe '|'
This code may Help you:
$string = '।।ॐम्।।';
$newData = str_replace('|','',$string);
Thanks for everyone . I got answer.
This worked for me.
$str2 = str_replace('।','',$r[6]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.