204
204
// first remove the XML declaration
205
205
// merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages
206
$header = preg_replace( '/<\?xml.*?\?'.'>/', '', substr($this->message, 0, 100), 1);
207
$this->message = substr_replace($this->message, $header, 0, 100);
208
if (trim($this->message) == '') {
206
$header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 );
207
$this->message = trim( substr_replace( $this->message, $header, 0, 100 ) );
208
if ( '' == $this->message ) {
212
// Then remove the DOCTYPE
213
$header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 );
214
$this->message = trim( substr_replace( $this->message, $header, 0, 200 ) );
215
if ( '' == $this->message ) {
219
// Check that the root tag is valid
220
$root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) );
221
if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) {
224
if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) {
228
// Bail if there are too many elements to parse
229
$element_limit = 30000;
230
if ( function_exists( 'apply_filters' ) ) {
231
$element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit );
233
if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) {
211
237
$this->_parser = xml_parser_create();
212
238
// Set XML parser to take the case of tags in to account
213
239
xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);