Wednesday, May 4, 2011

UTF-8 characters in input fields

I haven't been able to write utf-8 characters to input fields using Watir. If anybody has, please comment!

For testing UTF-8 characters in input fields, I've created a small PHP script that:

1. Gets the web page.
2. Inserts UTF-8 string to input field value.
3. Displays the page.

Here is an example of the PHP script:

# proxy / url parameters
$proxyName = "proxy.com";
$proxyPort = "8080";
$requestURL = "http://mysite.com"
   
# create a new cURL resource
$ch = curl_init();
   
# set URL and other options
curl_setopt($ch, CURLOPT_PROXY, $proxyName);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxyPort);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_URL, $requestUrl);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);

# pass request
$htmlSource = curl_exec($ch);

# close cURL resource, and free up system resources
curl_close($ch);
   
# e.g. add / replace input field value with utf-8 string
$htmlSource = ereg_replace($replacethis,$replacewith,$htmlSource);
   
echo $htmlSource

No comments:

Post a Comment