export doctype from url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
katerina
Forum Newbie
Posts: 11
Joined: Wed May 14, 2008 1:41 pm

export doctype from url

Post 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?
Last edited by katerina on Sun May 18, 2008 10:41 am, edited 1 time in total.
katerina
Forum Newbie
Posts: 11
Joined: Wed May 14, 2008 1:41 pm

Re: export doctype from url

Post 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.
katerina
Forum Newbie
Posts: 11
Joined: Wed May 14, 2008 1:41 pm

Re: export doctype from url

Post by katerina »

one comment ?
nobody ?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: export doctype from url

Post by VladSun »

Code: Select all

function get_doctype($file_content)
{
    return preg_match('/"-\/\/W3C\/\/DTD(.*?)\/\/(?:\w+?)"/is', $file_content, $matches) ? $matches[1] : false;
}
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply