I need to remove all double quotes,single quotes using jQuery AJAX in with google language translator. when i change onchange() it does not translate the string or character if double quotes found,and i am also used in php but not getting expected result.
我需要删除所有双引号,使用jQuery AJAX和谷歌语言转换器的单引号。当我更改onchange()时,如果找到双引号,它不会转换字符串或字符,我也在php中使用,但不会得到预期的结果。
i am used php' string related function but not getting result
我使用了php的字符串相关函数,但没有得到结果。
HTML CODE :
HTML代码:
<select name="langid" id="langid<@=review_id@>" class="guest clearfix" style="width: 150px;height: 29px;" onchange='translate_text("<@=review_id@>","<@=review_title@>","<@=your_view@>","<@=neg_review@>");'>
PHP CODE :
PHP代码:
<?php
public function translate_text()
{
try
{
$positive = $_REQUEST['positivereview'];
$negative = $_REQUEST['negativereview'];
$title = $_REQUEST['title'];
$translate_into = $_REQUEST['lang'];
$var = new translate($translate_from,$translate_into);
$ar = array();
if($title)
{
$ar['title'] = $var->get($title);
}
if($positive)
{
$ar['positivereview'] = $var->get($positive);
}
if($negative)
{
$ar['negativereview'] = $var->get($negative);
}
print_r(json_encode($ar));
exit(0);
}
catch(Exception $e)
{
$this->log->logIt($this->module."-".""."-".$e);
}
}
?>
JS/JQUERY CODE :
JS / JQUERY代码:
function translate_text($review_id,$review_title,$your_view,$neg_review)
{
var sel = jQuery('#langid'+$review_id).val();
var url=serverurl+'index.php/feedback';
showLoadingBar();
if(sel == 0)
sel = 'en';
var passDataAsStr="opcode=translate_text&positivereview="+
$your_view+"&negativereview="+$neg_review+"&title="+$review_title+"&lang="+sel;
jQuery.ajax({
type: "POST",
url: url,
//async : false,
data: passDataAsStr,
success: function(response) {
hideLoadingBar();
// console.log(response);
jQuery('#btnclose'+$review_id).show();
jQuery('#trans_div'+$review_id).show();
var res = jQuery.parseJSON(response);
console.log(res['title']);
console.log(res['positivereview']);
console.log(res['negativereview']);
jQuery('#titleid_'+$review_id).text(res['title']);
jQuery('#positiveid'+$review_id).text(res['positivereview']);
jQuery('#negativeid'+$review_id).text(res['negativereview']);
}
});
}
When I want change the language translator it does not change,i am using like this var $review_title = this.$review_title.replace(/['"]+/g, "");
but i don't know how to pass `.replace() in parameter in ajax jquery. to change the review title in jquery and in php also not get result
当我想要改变语言转换器时它不会改变,我就像这样使用var $review_title = this.$review_title。替换(/['”)+ / g,”“);但是我不知道如何在ajax jquery参数中传递' .replace()。在jquery和php中修改评审标题也不会得到结果
i want this type of output.
我想要这种类型的输出。
input like this : "New "home" away from home when in village"
输入如下:“新家园”远离家园时在乡村”
output must be this : New home away from home when in village
产出一定是这样的:在农村时,新家离家
Any body having any idea please help to sort it out. Thanks
任何有意见的人请帮忙解决。谢谢
to sort out in php
or jquery
side or any html special character
在php或jquery或任何html特殊字符中进行排序。
2 个解决方案
#1
1
Use str.replace(/"|'/g,'');
to remove double or single quotes:
使用“| str.replace(/ / g,”);删除双引号或单引号:
var str = `New "home" away from home when in village's`;
var res = str.replace(/"|'/g,'');
console.log(res);
#2
1
you can use:
您可以使用:
$str = str_replace(array('\'', '"'), '', $str);
And If your string is having only characters and numbers then you can use:
如果你的字符串只有字符和数字,那么你可以使用:
$str = preg_replace("/[^a-zA-Z0-9 ]+/", "", html_entity_decode($str ));
#1
1
Use str.replace(/"|'/g,'');
to remove double or single quotes:
使用“| str.replace(/ / g,”);删除双引号或单引号:
var str = `New "home" away from home when in village's`;
var res = str.replace(/"|'/g,'');
console.log(res);
#2
1
you can use:
您可以使用:
$str = str_replace(array('\'', '"'), '', $str);
And If your string is having only characters and numbers then you can use:
如果你的字符串只有字符和数字,那么你可以使用:
$str = preg_replace("/[^a-zA-Z0-9 ]+/", "", html_entity_decode($str ));