简体   繁体   中英

PHP Regular expression function conflict

I've used php 4 function as spliti() as well as php 5 function preg_match . It shows output in my localhost (xampp version 1.7.2). But When I upload it to my server it shows nothing at preg_match and return false. I don't know why. Can anybody help me on this?

My function is for getting doctype and char-set of a html page. Functions are given below:

function GetContentType($Data) { // data as the html code
     print preg_match('@<meta\s+http-equiv="Content-Type"\s+content="([\w/]+)(;\s+charset=([^\s"]+))?@i', $Data, $matches);
    print var_dump($matches);
    if (isset($matches[3]))
        return $matches[3];
    else
        return "No Character set detected.";
}

function GetDocType($Data) { // Data as the html codes
    print preg_match('/<!DOCTYPE (\w.*)dtd">/is', $Data, $patterns);
    print var_dump($patterns);
    $Data = explode(" ", str_replace('"', "", $patterns[1]));
    $Data = $Data[0] . " " . $Data[3] . " " . $Data[4] . " " . $Data[5];
    return str_replace("//EN", "", $Data);
}

From the PHP documentation:

preg_match() 5.3.6 Returns FALSE if offset is higher than subject length.

I assume that will be the issue here...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM