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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.