如何在php中删除页面内容

如何在php中删除页面内容,php,Php,我从curl那里得到了一页,其中包含 <?xml version="1.0" encoding="UTF-8"?> <ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"> 我想删除这个标题 因此,我们需要帮助如何做到这一点 我尝试了stru_替换函数,但没有成功 $find1='/<?xml version="1.0" encodin

我从curl那里得到了一页,其中包含

<?xml version="1.0" encoding="UTF-8"?>
<ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
我想删除这个标题 因此,我们需要帮助如何做到这一点

我尝试了stru_替换函数,但没有成功

$find1='/<?xml version="1.0" encoding="UTF-8"?>/';
$find2='/<ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">/';
$contentx = str_replace($find1, '', $data,$count);

您不需要将“//”分隔符与str_replace一起使用,只需与正则表达式函数一起使用即可。删除开始和结束处的斜线

换言之:

$find1='<?xml version="1.0" encoding="UTF-8"?>';
$find2='<ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">';
$contentx = str_replace($find1, '', $data,$count);

使用explode函数可以更轻松地完成此操作

$dataArray = explode("\r\n", $data, 3); // adjust the delimiter if it's unix newline
$contentx = $dataArray[2];

str_replace中不需要分隔符,它不是一个正则表达式函数。为什么在引号后/之前有/在引号后/在引号之前?如果删除正则表达式分隔符,str_replace应该会成功。最好使用PHP中的一个来获得您想要的,而不是字符串替换您不想要的。