Replacing "ereg"

I have a piece of code that was working fine before my host upgraded php. The snippet is:
[php]// separate content from HTTP headers
if(ereg("^(.)\r?\n\r?\n", $this->httpData)) {
$this->debug(“found proper headers and document”);
$this->httpBody = ereg_replace("^[^<]
\r\n\r\n","", $this->httpData);
$this->debug("remove headers, body length: ".strlen($this->httpBody));
}
else {
$this->debug(“headers and body are not properly separated”);
$this->setError(‘headers and body are not properly separated’);
return false;
}
[/php]

I’ve changed the code to this, but now it’s going to the “else” block - something’s wrong:

[php]// separate content from HTTP headers
if(preg_match("/^(.)\r?\n\r?\n/", $this->httpData)) {
$this->debug(“found proper headers and document”);
$this->httpBody = preg_replace("/^[^<]
\r\n\r\n/","", $this->httpData);
$this->debug("remove headers, body length: ".strlen($this->httpBody));
}
else {
$this->debug(“headers and body are not properly separated”);
$this->setError(‘headers and body are not properly separated’);
return false;
}
[/php]

Try replacing the whole thing with something like this:

[php]list($this->httpHeader, $this->httpBody) = explode("\r\n\r\n", $this->httpData, 2);[/php]

Found it here:

Sponsor our Newsletter | Privacy Policy | Terms of Service