|
Posted by Jochem Maas on 09/29/05 01:51
Scott Fletcher wrote:
>>Aw!!! This is driving me nut...
>
>
> It still does.... :-)
>
>
>>get to grips with var_dump() ...
>
>
> Um.... Interesting thought...
>
>
>>($array.$suffix) will never be an array
>>$suffix .= "['".$key."']";
>
>
> Yea, you are correct... I was trying to integrate the coding and stumpled
> upon this. It's a mind-twisting task here.
>
>
>>Problem is I can't use the foreach() loop because it would include the
>>numeric value into the string, like <0>blah</0>...
>>
>>could you rephrase that in english?
>
>
> The arrays with ['NEWSFEED']['0']['MESSAGE']['1'] where the the two square
> brackets with numeric number on the 2nd and 4th square backet is to tell us
> how many of that tag name in the 1st and 3rd square bracket there are. If I
> am to convert that back into xml then those numeric square bracket isn't
> needed. Well, all is not lost. I had scraped it and came up with a new
> model. It work better than I thought but not too well. This is testcase
> #15..
>
> --snip--
> /*
> $xml_str = "<NewsFeed>";
> $xml_str .= " <Message>";
> $xml_str .= " <Comment>";
> $xml_str .= " <![CDATA[Comment #1]]>";
> $xml_str .= " </Comment>";
> $xml_str .= " </Message>";
> $xml_str .= " <Message>";
> $xml_str .= " <Comment>";
> $xml_str .= " <![CDATA[Comment #2]]>";
> $xml_str .= " </Comment>";
> $xml_str .= " </Message>";
> $xml_str .= "</NewsFeed>";
> */
>
the xml above is not structurally
the same as the array below !!!!
I'll bet your output has just one message
element right? or you have gone completely offtrack.
might be time you went here:
http://php.net/xml
http://php.net/dom
http://php.net/domxml
might be something there to help you out
especially if you give php5 a try.
> $array = array
> (
> 'NEWSFEED' => array
> (
> '0' => array
> (
> 'MESSAGE' => array
> (
> '0' => array
> (
> 'COMMENT' => array
> (
> '0' => array
> (
> 'VALUE' => 'Comment #1'
> )
> )
> ),
> '1' => array
> (
> 'COMMENT' => array
> (
> '0' => array
> (
> 'VALUE' => 'Comment #2'
> )
> )
> )
> )
> )
> )
> );
>
> function my_build_xml($xml_tree, $x)
> {
> global $xml_data;
> $x++;
>
> foreach($xml_tree as $key => $value)
> {
> if(is_array($value)) {
> if ($x % 2 != 0) {
> $xml_data .= str_repeat(" ",$x)."<".$key.">"."\r\n";
> my_build_xml($value, $x);
> $xml_data .= str_repeat(" ",$x)."</".$key.">"."\r\n";
>
> if ($key != 0) {
> $xml_data .= str_repeat(" ",$x)."<".$key.">"."\r\n";
> my_build_xml($value, $x);
> $xml_data .= str_repeat(" ",$x)."</".$key.">"."\r\n";
> }
> } else {
> my_build_xml($value, $x);
> }
> } else {
> if ($x % 2 != 0) {
> $xml_data .= str_repeat("
> ",$x)."<".$key.">".$value."</".$key.">"."\r\n";
> }
> }
> }
> }
>
> my_build_xml($array, "0");
>
> echo "\n<br><br>\n".$xml_data;
> --snip--
>
> The output doesn't match the one in the $array or $xml_str above. So, I'm
> now on testcase #16 with some revamping of the code and I'm not having much
> luck at it. Maybe you can help if you know of something here... :-)
>
Navigation:
[Reply to this message]
|