function encrypt_url($string)
	$key = "1AT2#mr(luv^iU3tp>"; 
	$result = '';
	for($i=0; $i<strlen($string); $i++)
		$char = substr($string, $i, 1);
		$keychar = substr($key, ($i % strlen($key))-1, 1);
		$char = chr(ord($char)+ord($keychar));
	return urlencode(base64_encode($result));

Normally through PHP code i got encrypted value -> pqW1xGxSnOmf46Pqw9zJYdffqw%3D%3D

When i try through javascript getting some wrong output

// Javascript

var my_url=document.getElementById('url').value;

// my_url='';

var final_post_url=<?=encrypt_url(my_url)?>;

plz help me how to get correct encrypted data through java script?

You can't (normally) access javascript variables form php. You'll need to write that function in javascript, and call that function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.