How to check string encoding?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check string encoding?
# 1  
Old 08-02-2012
Question How to check string encoding?

I want to check if the string is WINDOWS-1251 or UTF-8

can you help me to find the string encoding???

or maybe to get URL Content-Type charset with wget?

this is my function on PHP

PHP Code:
function check_utf8($str) { 
    
$len strlen($str); 
    for(
$i 0$i $len$i++){ 
        
$c ord($str[$i]); 
        if (
$c 128) { 
            if ((
$c 247)) return false
            elseif (
$c 239$bytes 4
            elseif (
$c 223$bytes 3
            elseif (
$c 191$bytes 2
            else return 
false
            if ((
$i $bytes) > $len) return false
            while (
$bytes 1) { 
                
$i++; 
                
$b ord($str[$i]); 
                if (
$b 128 || $b 191) return false
                
$bytes--; 
            } 
        } 
    } 
    return 
true

I want to make it in shell

Thank you!!!

Last edited by sanantonio7777; 08-02-2012 at 09:25 AM..
# 2  
Old 08-02-2012
What's your system? What's your shell? This will be a lot harder in some shells than others, most can't directly turn a character into an integer value like that.

If perl is available I'd suggest using that.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 08-02-2012
Im with OS X

this is my code
Code:
wget --server-response --spider -t 1 --timeout=1   "$fieldurl" 2>&1 | egrep -i "utf"

its ok for now Smilie
This User Gave Thanks to sanantonio7777 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Url encoding a string using sed

Hi I was hoping some one would know if it is possible to url encode a string using sed? My problem is I have extracted some key value pairs from a text file with sed, and will be inserting these pairs as source variables into a curl script to automatically download some xml from our server. My... (5 Replies)
Discussion started by: Paul Walker
5 Replies

2. Solaris

View file encoding then change encoding.

Hi all!! I´m using command file -i myfile.xml to validate XML file encoding, but it is just saying regular file . I´m expecting / looking an output as UTF8 or ANSI / ASCII Is there command to display the files encoding? Thank you! (2 Replies)
Discussion started by: mrreds
2 Replies

3. Shell Programming and Scripting

Check file for string existence before appending it with string

I want to append file with a string but before doing that i want to check if this string already exist in that file.I tried with grep on Solaris 10 but unsuccessful.Man pages from grep seems to suggest if the string is found command status will be 0 and if not 1.But i am not finding it.May be i... (2 Replies)
Discussion started by: sahil_shine
2 Replies

4. Shell Programming and Scripting

check if one string comes before another

I want to search a file to check if there is string a before string b: string a, b might not necessarily be in the file, and to return a boolean string a (any text) string b i have tried for an hour to do this with perl, grep, etc. but no luck grep doesnt search for patterns... (7 Replies)
Discussion started by: vanessafan99
7 Replies

5. Shell Programming and Scripting

python - string encoding error

I'm trying to pull a google calendar (successful) and then put the contents into a mysql db (almost successful). On one of the field I keep getting an encode error: #!/usr/bin/python from xml.etree import ElementTree import gdata.calendar.data import gdata.calendar.client import... (12 Replies)
Discussion started by: unclecameron
12 Replies

6. Shell Programming and Scripting

How to find the file encoding and updating the file encoding?

Hi, I am beginner to Unix. My requirement is to validate the encoding used in the incoming file(csv,txt).If it is encoded with UTF-8 format,then the file should remain as such otherwise i need to chnage the encoding to UTF-8. Please advice me how to proceed on this. (7 Replies)
Discussion started by: cnraja
7 Replies

7. Shell Programming and Scripting

how to check string of character

how can i check whether variable contains only character from a-z or A-Z....if my variable contains any alpha numeric, numeric or any character with some special one i.e. *%&@! etcetera etcetera....then it should show me please enter only characters...... Let my variable var1="abc77}|" then... (9 Replies)
Discussion started by: manas_ranjan
9 Replies

8. Shell Programming and Scripting

Check for empty string

Hello All, I have written shell script whcih at the max 3 parameters. When only one commandline argument and other two command line arguments are passed as empty string like eg : archive ' ' ' ' Then i need to check whether the commandline... (12 Replies)
Discussion started by: rahman_riyaz
12 Replies

9. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies
Login or Register to Ask a Question