PHP将空属性转换为文本或数字

PHP将空属性转换为文本或数字,php,xml,Php,Xml,我有一个带有属性的xml文件 XML文档 <SET name="John" lastname="Steve" city="New York" Country=""/> 我想从国家/地区获取空内容,并将其转换为默认文本(如USA) 我将使用str_replace来进行此替换 问题是我不知道如何获取空属性,比如if是empy var_dump 谢谢 转换文件 $filexml = 'file.xml'; if (file_exists($filexml)){ $

我有一个带有属性的xml文件

XML文档

<SET name="John" lastname="Steve" city="New York" Country=""/>
我想从国家/地区获取空内容,并将其转换为默认文本(如USA)

我将使用str_replace来进行此替换

问题是我不知道如何获取空属性,比如if是empy var_dump

谢谢

转换文件

$filexml = 'file.xml';
    if (file_exists($filexml)){
        $xml = simplexml_load_file($filexml);
$file = fopen('clients.csv', 'w');
        $header = array('Name', 'LastName', 'City', 'Country');
fputcsv($file, $header, ',', '"');
foreach ($xml->SET as $set){
$item = array();
            $value1 = $set->attributes()->name;
            $value2 = $set->attributes()->lastname;
            $value3 = $set->attributes()->city;
            $value4 = $set->attributes()->Country;

$search_country= array('','10','12')
$replace_country = array('USA','Argentina','Canada')
$item[] = $value1;
$item[] = $value2;
$item[] = $value3;
$item[] = str_replace($search_country, $replace_country, $value4);

fputcsv($file, $item, ',', '"');    
        }
        fclose($file);
    }

使用
empty
检查值是否为空

$value4 = empty($set->attributes()->Country) ? "USA" : $set->attributes()->Country;

您用于转换的代码在哪里?您必须提供有关如何解析xml文件的元素和属性的更多信息…嗨,爸爸,这是得到的:HTTP错误500(内部服务器错误):我的错误,对不起,这就像我忘了一样工作)谢谢爸爸
$value4 = empty($set->attributes()->Country) ? "USA" : $set->attributes()->Country;