Jump to content

encode string


manix

Recommended Posts

Alright, I read like 500 articles and threads about this and none of them worked.

 

I have a string of cyrillic characters which I need to pass to another page via post ajax which apparently does not support cp1251 charset so I figured I needed to encode the string before passing it, and I did utf8_encode and guess what, it didn't work because that encodes cyrillic characters to some other cyrillic looking characters and when they're being passed via post they become something like "PPP?!?PPP". So my question is what encoding do I need to use to pass cyrillic characters with jquery post ajax

Link to comment
https://forums.phpfreaks.com/topic/244481-encode-string/
Share on other sites

well It's all mixed..

 

 

<?php
if(isset($_POST['search']))
  {
  $search = $_POST['search']; // this is the correct string which I send from a form in another page
   ..here I echo some stuff..
?>
<script type="text/javascript">
$.post('vicove.php', { 
						page: 1,
						order: 4,
						search: $('#searchhidden').val() // this is still the correct string
					},
function(returned) {
if(returned.length>100)
	{
	$('#results').html(returned).show();
	}
});
</script>
<?php
}
?>

 

here's the part where it messes up

 

vicove.php

<?php
....
$ordernumber=$_POST['order'];	
switch($ordernumber)
	{
	case 4:
	$viewuser = $_POST['search']; // alright here is the problem, now it's ruined
...
?>

Link to comment
https://forums.phpfreaks.com/topic/244481-encode-string/#findComment-1255739
Share on other sites

Solved, used urlencode() and urldecode()

 

sending

$.post('vicove.php', { 
						page: 1,
						order: 4,
						param1: "<?php echo urlencode($search); ?>"
					},
function(returned) {
if(returned.length>100)
	{
	$('#results').html(returned).show();
	}
});

 

receiving

<?php
$search = urldecode($_POST['param1']);
?>

Link to comment
https://forums.phpfreaks.com/topic/244481-encode-string/#findComment-1255781
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.