"z1" <my@email123.netwrote in message
news:46***********************@roadrunner.com...
hi -
i am going to try to use regular expressions to get my values.
i am frustrated that the formart of the file doesnt seem to be
able to be parsed by simplexml.
thanks anyways,
listen jim, don't try to access the arrays by index. just use a foreach.
however, if you just want to use regex for simplicity and you don't need to
know attributes and such, try these:
==========
hint: segment is a node
<?xml>
<root>
<recordswould be a 'segment'...a 'single segment'
<record /would be one of many 'segments', or 'multiple segments'
<record />
<record />
</records>
</root>
$records = getSingleSegment('records', $xml);
$records = getMultipleSegments('record', $records);
foreach ($records as $record)
{
// you get the idea
}
==========
function getMultipleSegments($segment, $xml)
{
$pattern = "/<(" . $segment . ")>(.*?)<\/\\1>/si";
preg_match_all($pattern, $xml, $matches);
foreach ($matches[2] as $content)
{
$output[] = $content;
}
return $output;
}
function getMultipleSegmentNames($xml)
{
$output = array();
$pattern = "/<([^>]+)>.*?<\/\\1>/si";
preg_match_all($pattern, $xml, $matches);
foreach ($matches[1] as $content)
{
$output[] = $content;
}
return $output;
}
function getSegmentValue($xml, $emptyDefault = '')
{
$pattern = "/<([^>]+)>(.*?)<\/\\1>/si";
preg_match($pattern, $xml, $match);
$value = $match[2];
if ($value == ''){ $value = $emptyDefault; }
return htmlDecode($value);
}
function getSingleSegment($segment, $xml)
{
$output = '';
$pattern = "/<(" . $segment . ")>(.*?)<\/\\1>/si";
preg_match_all($pattern, $xml, $matches);
foreach ($matches[0] as $content)
{
$output .= $content;
}
return $output;
}
function getSingleSegmentName($xml)
{
$output = '';
$pattern = "/<([^>]+)>.*?<\/\\1>/si";
preg_match($pattern, $xml, $match);
return $match[1];
}