问题描述:

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"]+))[email protected]', $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...

相关阅读:
Top