Page 1 of 1

export doctype from url

Posted: Sat May 17, 2008 7:56 am
by katerina
Hi ,
I have a variable that saves the whole line doctype of a page using regular expression

Code: Select all

function get_doctype($file){
    $h1tags = preg_match('/<!DOCTYPE (\w.*)dtd">/is',$file,$patterns);
    $res = array();
    array_push($res,$patterns[0]);
    array_push($res,count($patterns[0]));
    
    return $res;
}
So the variable contains the string "<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">"

But I would like to save only SVG 1.1 Basic.

So I am trying to make a regular expression for it like this :

$res = str_replace("(.*)//DTD","", $res);
$res = str_replace("(^//EN) .* (dtd\")$","", $res);

What am I doing wrong ?

Thank you

P.S. : If you know could you help me and for encoding?

Re: export doctype from url

Posted: Sun May 18, 2008 8:49 am
by katerina
Could anyone help me to make a case statement ?

I am trying something like

Code: Select all

switch($res)
{
   case  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" : $res = "XHTML 1.0 Strict";
break;
}
But it does not work.

Re: export doctype from url

Posted: Mon May 19, 2008 6:03 am
by katerina
one comment ?
nobody ?

Re: export doctype from url

Posted: Mon May 19, 2008 10:05 am
by VladSun

Code: Select all

function get_doctype($file_content)
{
    return preg_match('/"-\/\/W3C\/\/DTD(.*?)\/\/(?:\w+?)"/is', $file_content, $matches) ? $matches[1] : false;
}