I'm trying to do a rawurlencode, but it is not working as I though it would do. The data I'm trying to encode is coming from javascript and I stored the information on a variable. The value of the variable seems to be correct (did echo in a couple of places) everywhere except after the encoding. It seems that instead of using the value of the variable for the encoding is using the script that generated the value and encoding that.
<?php
//getting the author name using javascript
$author1="
<script type=\"text/javascript\">
jsauthor1 = document.getElementsByTagName(\"span\")[8].innerText;
document.write(jsauthor1);
</script>";
// checking Author name is correct
echo $author1." : Author name after Javascript extraction". "<br>";
$params = array(
"Service" => "AWSECommerceService",
"Operation" => "ItemSearch",
"AWSAccessKeyId" => "AKIAJSGKPYO6HFNCED7A",
"AssociateTag" => "hobbytryout0a-20",
"SearchIndex" => "Books",
"Sort" => "price",
"Author" => $author1,
);
// checking that array have correct values (taking the value of "$author" correctly)
echo $params[Author]." : Author name after creating array using variable <br>";
// convert $params[Author] to a String to test the encoding
$test = (string)$params[Author];
echo $test." : Author name after creating string from array"."<br>";
echo rawurlencode($test)." : Author name after rawurlencode"."<br>";
?>
This is what I get:
Jules Verne : Author name after Javascript extraction
Jules Verne : Author name after creating array using variable
Jules Verne : Author name after creating string from array
%20%0A%20%20%20%20%3Cscript%20type%3D%22text%2Fjavascript%22%3E%0A%20%20%20%20jsauthor1%20%3D%20document.getElementsByTagName%28%22span%22%29%5B8%5D.innerText%3B%0A%20%20%20%20document.write%28jsauthor1%29%3B%0A%20%20%20%20%3C%2Fscript%3E : Author name after rawurlencode
Shouldn't it be Jules%20Verne ?
Thanks