当时在网上找了一个CDATA的转换器, 修改之后, 将CDATA标签给过滤掉。如下
复制代码 代码如下:
// States:
//
// 'out'
// ' // ' // ' // ' // ' // ' // ' // 'in'
// ']'
// ']]'
//
// (Yes, the states a represented by strings.)
//
$state = 'out';
$a = str_split($xml);
$new_xml = '';
foreach ($a AS $k => $v) {
// Deal with "state".
switch ( $state ) {
case 'out':
if ( ' $state = $v;
} else {
$new_xml .= $v;
}
break;
case ' if ( '!' == $v ) {
$state = $state . $v;
} else {
$new_xml .= $state . $v;
$state = 'out';
}
break;
case ' if ( '[' == $v ) {
$state = $state . $v;
} else {
$new_xml .= $state . $v;
$state = 'out';
}
break;
case ' if ( 'C' == $v ) {
$state = $state . $v;
} else {
$new_xml .= $state . $v;
$state = 'out';
}
break;
case ' if ( 'D' == $v ) {
$state = $state . $v;
} else {
$new_xml .= $state . $v;
$state = 'out';
}
break;
case ' if ( 'A' == $v ) {
$state = $state . $v;
} else {
$new_xml .= $state . $v;
$state = 'out';
}
break;
case ' if ( 'T' == $v ) {
$state = $state . $v;
} else {
$new_xml .= $state . $v;
$state = 'out';
}
break;
case ' if ( 'A' == $v ) {
$state = $state . $v;
} else {
$new_xml .= $state . $v;
$state = 'out';
}
break;
case ' if ( '[' == $v ) {
$cdata = '';
$state = 'in';
} else {
$new_xml .= $state . $v;
$state = 'out';
}
break;
case 'in':
if ( ']' == $v ) {
$state = $v;
} else {
$cdata .= $v;
}
break;
case ']':
if ( ']' == $v ) {
$state = $state . $v;
} else {
$cdata .= $state . $v;
$state = 'in';
}
break;
case ']]':
if ( '>' == $v ) {
$new_xml .= htmlentities($cdata);
# $new_xml.= $cdata;
// $new_xml .= str_replace('>','>',
// str_replace('>',' // str_replace('"','"',
// str_replace('&','&',
// $cdata))));
$state = 'out';
} else {
$cdata .= $state . $v;
$state = 'in';
}
break;
} // switch
}
//
// Return.
//
return $new_xml;