错误无法显示

时间:2012-07-08 16:52:26

标签: php xml

我有这种xml格式:

<searches> 

<search>
<name> stephen </name>
<address> box 23 </address>
<sector> IT </sector>
<contacts>+233247764939 </contacts>

<search>
<name> stephen </name>
<address> box 23 </address>
<sector> IT </sector>
<contacts>+233247764939 </contacts>

<searches>

当找不到名称节点的值时,我想向用户显示错误。 我已经尝试使用下面的代码,但似乎echo语句没有执行,因此当名称节点值为空或不包含值时,空屏幕显示没有echo消息。有关此代码的任何帮助吗? 注意:如果名称没有价值,则表示公司不存在。 此代码将$ objj的值返回到下一个php脚本。

以下是完整的代码:

<?php 
function processing($term){
$params = array ('username' => 'username', 'password' => 'password', 'term'=> $term); 
// Build Http query using params
$query = http_build_query ($params);
// Create Http context details
$contextData = array (
'method' => 'POST',
'header' => "Connection: close\r\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"Content-Length: ".strlen($query)."\r\n",
'content'=> $query );
// Create context resource for our request
$context = stream_context_create (array ( 'http' => $contextData ));
print_r($context);
// Read page rendered as result of your POST request
$result =  file_get_contents (
'http://infolinetest.nandiclient.com/search/searches/requestData.xml',  // page url
false,
$context);
// Server response is now stored in $result variable so you can process it

$obj = @simplexml_load_string($result);

 return $obj
 }
 ?>


//the outputting is done in this script

<?php  $objj = processing ($term); ?>
<div data-role="listview">
<ul data-role="listview" data-theme="g" data-inset="true" class="ui-listview ui-    listview-inset ui-corner-all ui-shadow">
<a href="" data-role="button" data-theme="g" data-inset="true"><strong>Search     Results</strong></a>
<?php if ($objj){    ?>        
<?php foreach(@$objj as $searches):?>
<li> <a href="Result_Selected.php?company=<?php echo $searches ->     name.'<br/>'.$searches->sector.'<br/>'.$searches ->address.'<br/>'.$searches ->     contacts.'<br/>'; ?>" data-role="button"><?php echo( $searches -> name).'<br/>'.$searches -    > sector ?></a></li>
<?php endforeach ?>
<a data-ajax="false" href="#top" data-role="button"  name= "smt"><strong>End Of List...    </strong></a>

<?php } else if(empty($objj)||($objj==null)||($objj->name=="")){    ?>

<?php  echo "hello company not found.try again"; } ?>

</ul>

0 个答案:

没有答案