...

View Full Version : How to find character encoding in any site



Gaurav.joshi
08-28-2009, 12:10 PM
Hi All,
I need to know, how can we get character encoding in any site through coding.

Actually i need to add an option in my website, in which i am entering a domain name(url of any website i.e. "http://www.yahoo.com") and through coding i have to find out the character encoding, doctype, frameset.. etc of the entered URL.
OR
Are there any such links which can help me out to get these parameters directly by passing the url only.
Can anyone please help me out to get the parameters of any site.......:)
waiting for ur reply`s

Thanks
gaurav joshi

barkermn01
08-28-2009, 01:24 PM
I Respectfully Disagree

Create a php page that Finds them out,

That outputs like so for example
E.G
//character encoding||doctype||frameset
UTF-8||doctype||frameset

Then AJAX(XMLHttpRequest)http://www.w3schools.com/ajax/
to get the string from php use some thing likea $_GET['url'] you want to check in your php file,
Then get your responseText from your AJAX and split('||'); this will then give you an array

array[0] = Encoding
array[1] = doctype
array[2] = frameset

And do what you will from there -- this is a long way about doing it but it works,

Philip M
08-28-2009, 01:26 PM
I don't see how that is possible without loading the page.

Using Javascript, this will detect the DOCTYPE:-


<script type = "text/javascript">

function versionInfo()
{
this.xhtml="";
this.version="";
this.importance="";
}
function detectDoctype(){
var re=/\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi;
var myversionInfo=new versionInfo();
//Just check for internet explorer.
if(typeof document.namespaces != "undefined"){
if(document.all[0].nodeType==8)
re.exec(document.all[0].nodeValue);
else
return null;
}else{
if(document.doctype != null)
re.exec(document.doctype.publicId);
else
return null;
}
myversionInfo.xhtml=RegExp.$1;
myversionInfo.version=RegExp.$2;
myversionInfo.importance=RegExp.$3;
return myversionInfo;
}
var myversionInfo=detectDoctype();
if(myversionInfo != null){
alert(myversionInfo.xhtml);
alert(myversionInfo.version);
alert(myversionInfo.importance);
}
else{
alert("There is no DOCTYPE in the code!");
}

</script>

barkermn01
08-28-2009, 01:47 PM
I don't see how that is possible without loading the page.

Using Javascript, this will detect the DOCTYPE:-


<script type = "text/javascript">

function versionInfo()
{
this.xhtml="";
this.version="";
this.importance="";
}
function detectDoctype(){
var re=/\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi;
var myversionInfo=new versionInfo();
//Just check for internet explorer.
if(typeof document.namespaces != "undefined"){
if(document.all[0].nodeType==8)
re.exec(document.all[0].nodeValue);
else
return null;
}else{
if(document.doctype != null)
re.exec(document.doctype.publicId);
else
return null;
}
myversionInfo.xhtml=RegExp.$1;
myversionInfo.version=RegExp.$2;
myversionInfo.importance=RegExp.$3;
return myversionInfo;
}
var myversionInfo=detectDoctype();
if(myversionInfo != null){
alert(myversionInfo.xhtml);
alert(myversionInfo.version);
alert(myversionInfo.importance);
}
else{
alert("There is no DOCTYPE in the code!");
}

</script>

You could try using an Iframe, should be able to get what you need out of that if you can still acceess Iframe sourceCode dont know not used iframes in years



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum