Jump to content

Archived

This topic is now archived and is closed to further replies.

Zharvek

Help with an Array problem?

Recommended Posts

Hello all, I have (think it is) an array problem. I am trying to create an component for a CMS system, but thats not what matters... I have collected some information, and code examples, and found some scripts to read an bookmark XBEL xml file, and output it nicely, using no XSL stylesheet, just PHP.

My problem is that I cannot find out how to modify this script to pull more data available from the file.

Currently it will pull, the title, url, and folder the link resides in, and prints it to the browser nicely. I need it to also grab and print the description.

Here is what I have now:

[code]
<?php

global $database;
$query = "SELECT * FROM jos_ablinks";
$database->setQuery( $query );
$rows = $database->loadObjectList();
$row = $rows[0];
$simple=@join('',@file($row->filepath));

$p = xml_parser_create();
xml_parse_into_struct($p, $simple, $vals, $index);
xml_parser_free($p);

$bm=array();

foreach ($index['FOLDER'] as $k=>$v)
{
$bm[$v]='DDDODDD';
}

foreach ($index['TITLE'] as $k=>$v)
{
$bm[$v]=$vals[$v]['value'];
}

foreach ($index['BOOKMARK'] as $k=>$v)
{
if (is_array($vals[$v]['attributes']))
{
$bm[$v]=$vals[$v]['attributes']['HREF'];
}
}

ksort($bm);

$l=true;
foreach ($bm as $k=>$v)
{    
if ($v=='DDDODDD')
{
if (!$l)
{
$l=true;
}
} else {
if (substr($v,0,4)=='http')
{
$lastlink=$v;
} else {
if (strlen(trim($v))>0)
{
if ($l)
{
$l=false;
if ($v==$row->ignored){}else{
echo '<tr><td><h4>'.htmlspecialchars($v).'</h4></td><tr>';
}
} else {
echo '<tr><td><a href="'.$lastlink.'">'.htmlspecialchars($v).'</a></td></tr>';
}
}
}
}
}

$vals=array();
$index=array();
?>[/code]

Sorry if that was long, I have tried adding an

[code]foreach ($index['DESC'] as $k=>$v)
{
$bm[$v]=$vals[$v]['value'];
}[/code]

Under the one with $index['TITLE'] and after playing around with some code, I got it to print the very last DESC in the XML file, but not a DESC for each item in the xml file. I hope I am being clear with it, I just want to be able to put the DESC in here

[code]<tr><td><a href="'.$lastlink.'">'.htmlspecialchars($v).'</a></td></tr>[/code]

to look something like

[code]<tr><td><a href="'.$lastlink.'">'.htmlspecialchars($v).'</a><br />'.$desc.'</td></tr>[/code]

Thanks in advance if anyone can help. :-)

Share this post


Link to post
Share on other sites
Seems like the data is getting parsed into the variable $index ..

So my plan of action would be to figure out everything that $index contains. Seems logical, no?

[code]print "<pre>";
print_r($index);
print "</pre>";[/code]

Always very useful.. let me know if you have any further questions.

Also.. Your tabbing is terrible and makes me not want to read your code, at all.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.