2012-03-22 60 views
0

刪除內容我從包含如何從頁面在PHP

<?xml version="1.0" encoding="UTF-8"?> 
<ipinfo xmlns="http://data.quova.com/1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"> 

我想刪除這個頭 因此需要幫助該怎麼做了捲曲的一頁。

我試過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); 
+1

無需在'str_replace'分隔符,它不是一個正則表達式功能 – 2012-03-22 20:00:58

+0

爲什麼你'/'的前/後前引號? – 2012-03-22 20:01:44

+0

如果刪除了正則表達式分隔符,'str_replace()'應該成功。 – 2012-03-22 20:01:51

回答

0

你並不需要使用「/ /」分隔符與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); 
+0

感謝它幫助我:) – user114500 2012-03-22 21:00:06

0

您可以使用explode()功能做的更容易。

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