lior r
lior r

Reputation: 2290

UTF8 to CP1255 conversion

I am trying to convert a UTF-8 string to CP1255 (Hebrew)

I have tried running the following (I'm using detect_encoding because some of my inputs are not UTF-8):

foreach($param as $key=>$value){
    $newval = iconv(mb_detect_encoding($value),"cp1255",$value);
    $querystr .= $key."=".$newval."&";
}

Anyway, the result is that all the Hebrew characters returns the nice � symbol, And all others(English/numbers) are as expected and wanted remain intact.

How can I do this properly?

Upvotes: 3

Views: 835

Answers (1)

lior r
lior r

Reputation: 2290

I have found a solution:

foreach($param as $key=>$value){
    $value_encoding = mb_detect_encoding($value);
    if($value_encoding == "UTF-8"){
        $newval = iconv($value_encoding,"cp1255",$value);
    }else{
        $newval = $value;
    }
    $endpoint = add_query_arg($key,$newval,$endpoint);
}

$content = file_get_contents($endpoint);

Upvotes: 6

Related Questions