2011-10-03 34 views
2

使用響應我在這在同一個PHP文件

第一部分中的一個單一的PHP文件:服務器產生一些輸出。

第二部分:使用服務器生成的輸出並提交信息。

我做了什麼:

文件名:abc.php

<?php 
//first part 
based on the information here server generates some output say: 
111 success: id:104.123/12345678 |value:10000045 

//second part 
i will be using the output generated in the first part. 
what i have done is something like this 
$server_said = file_get_contents('http://http://abc.php'); 
//abc.php is the file name 
if (preg_match_all('/104.123\:(\d*)/', $server_said, $matches)) 
//i want to display only 104.123/12345678 part 
{ 
$input = $matches[1]; 
} 
$xmlfile = '<?xml version="1.0" encoding="UTF-8"?> 
<identifier identifierType="id">'.$input.'</identifier>'; 

?> 

錯誤:在$輸入沒有顯示預期的結果,它只是停留爲$輸入

我怎樣才能做到這一點?

我不確定上面寫的代碼可能是錯誤的。

+0

你在哪裏試圖提交信息? – 3emad

+0

@ 3emad ..它是一個服務器,它用一個id來確認..這個id應該嵌入在XML文件中。 –

回答

1

正則表達式失敗,正確的是:

if (preg_match_all('/\d+\.\d+\/\d+/', $server_said, $matches)) 

還有,當你的輸出XML,u需要改變你的頭什麼如下:

header('Content-type: text/xml'); 
+0

preg_match_all('/ 104.123 \ d + \。\ d + \/\ d + /',$ server_said,$匹配)...我沒有嘗試這樣的運氣...沒有價值顯示在$輸入...我認爲我的方法有一些錯誤... –

+0

我有頭.. –

+0

我有已經測試了我寫的正則表達式,並且它可以從您給出的示例中運行,我希望看到實際的代碼,您是否可以粘貼到pastebin.com – 3emad