Page 1 of 1

PHP ARRAY PROBLEM!!

Posted: Thu Aug 28, 2008 9:10 am
by leathrm
Hello i am tryin to declare an array in a php document that will be looped through displaying only the specified elements that i want from an php xml generated file, only thing is i can't get the dman thing working!!

the array is declared in a .property doc and i am tryin to pull the array in to the php file

this is a section of the code from the php doc.

$a=array($config["group1.projects"]);

if( $rss === true )
{
echo "<item>\n<title>${f_name}, ${lResult}</title>\n";
# echo "<description>${status}.</description>\n";
echo "<description>${lResult}</description>\n";
echo "<pubDate>".($lAttempt !== "" ? date(DATE_RFC2822, $lastAttempt) : "")."</pubDate>\n";
echo "<link>".$config["url.prefix"]."?project=".
urlencode($f_name)."&log=".$lLog."</link>\n";
echo "</item>\n";
}

else foreach ($a as $z)
if ($z == $f_name) /*fname is the location of the corressponding file name
{
echo "<group1>";
echo "<project><name>".$f_name."</name><status>${status}</status>";
echo "<latestresult>".$lResult."</latestresult>";
echo "<latestsuccess>".$lSuccessfulBuild."</latestsuccess>";
echo "<latestattempt>".($lAttempt !== "" ? date($config["dateformat"], $lastAttempt) : "")."</latestattempt>";
echo "<latestlabel>".$lLabel."</latestlabel>";
echo "<latestlog>".$lLog."</latestlog>";
echo "</project>\n";
echo "</group1>";


this is the declaration in the .property doc.

group1.projects = "bnrClientConsole", "bnrCtlDotNet", "bnrCtlW32", "bnrFlash"
group1.name = PC Software

Re: PHP ARRAY PROBLEM!!

Posted: Sat Aug 30, 2008 4:46 am
by greyhoundcode
I'm not 100% clear about what you're doing here, but personally I would remove the inverted commas in your .property file and inspect it using string functions (alternatively leave the inverted commas in place and use PCRE, though it is slightly slower).

The lines inside your example .property file seem to have this syntax:

name = value1, value2

So if you read it into a string (file_get_contents) and then explode it once to seperate the name from the values - $result = explode("=", $line); - then you should end up with all the values inside $result[1].

One more explosion - $valueArray = explode(",", $result[1]); - should provide you with an array of the values you are after.