# Making a XML Manager in PHP

**URL:** https://forum.kirupa.com/t/making-a-xml-manager-in-php/262038
**Category:** programming
**Created:** [June 2, 2008, 8:57pm UTC](https://forum.kirupa.com/t/making-a-xml-manager-in-php/262038 "2008-06-02T20:57:38Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![k77](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@k77](https://forum.kirupa.com/u/k77)
#### Post date: [June 2, 2008, 8:57pm UTC](https://forum.kirupa.com/t/making-a-xml-manager-in-php/262038/1 "2008-06-02T20:57:38Z")

</div>

Hello,

Having trouble with a class… new to PHP I know your probably rolling your eyes, big move from .NET.

```php
    function end_element ($khalid, $element) {
        $element = strtolower($element);
        if ($this->ends_data[$element]) {
            $this->data[] = $this->data;
            $this->data = array();
        }
        $this->active_field = '';
    }
    
    function ccdata ($khalid, $text) {
        if ($this->data_type[$this->active_field] === 2) {
            $this->data[$this->active_field][] = $text;
        } elseif ($this->data_type[$this->active_field] === 1) {
            $this->data[$this->active_field] .=$text;
        }            
    }

function $display() {
        echo '<table border="0">
';
        foreach ($this->data as $image) {
            echo '<tr>';
            $image = join(',', $image['image']);
            printf("<th>
                        <a href='%s'>%s</a>
                    </th>
                    <td>
                        %s
                    </td>
                 </tr>
",
                 $_SERVER['PHP_SELF'] . '?pic=' . $image['pic'],
                 $image['caption'],$image);
            echo "</tr>
";
        }
    }

```

The snippet is basically part of a class. It displays

> **Parse error** : syntax error, unexpected T\_VARIABLE, expecting T\_STRING in **/localhost/admincp.php** on line **392**

Line 392 is the Display function

Please anyone?

---

<div class="post-metadata">

### Author: ![k77](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@k77](https://forum.kirupa.com/u/k77)
#### Post date: [June 3, 2008, 6:01pm UTC](https://forum.kirupa.com/t/making-a-xml-manager-in-php/262038/2 "2008-06-03T18:01:19Z")

</div>

```php

    function show_image ($pic) {
        foreach ($this->data as $image) {
            if ($image['pic'] !== $pic) {
                continue;
            }
            
            $image = join(',', $image['image']);
            printf("<b>%s</b> by %s.<br>", $image['caption'], $image);
            printf("Picture %s<br>", $image['pic']);
           ##419 printf("URL %s<p>
", image['url']); 
## Parse error: syntax error, unexpected '[' in admincp.php on line 419
        }
?>
<a href="<?= $_SERVER['PHP_SELF'] ?>">Back</a> to full list.</p>

```

Thanks for the welcome. This a sweet scripting language. The compiler is pretty friendly. Is there a PHP Studio other than Zend? Something like Visual Studio to manage PHP, Pear, MySQL etc…

---

<div class="post-metadata">

### Author: ![k77](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@k77](https://forum.kirupa.com/u/k77)
#### Post date: [June 3, 2008, 9:10pm UTC](https://forum.kirupa.com/t/making-a-xml-manager-in-php/262038/3 "2008-06-03T21:10:58Z")

</div>

…issues with my error?

```php
 printf("URL %s<p>
", image['url']); 
          

```

> Parse error: syntax error, unexpected ‘[’ in admincp.php on line 419

Walay Kum Salam

---

<div class="post-metadata">

### Author: ![kdd](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@kdd](https://forum.kirupa.com/u/kdd)
#### Post date: [June 4, 2008, 7:18am UTC](https://forum.kirupa.com/t/making-a-xml-manager-in-php/262038/4 "2008-06-04T07:18:37Z")

</div>

Just to clarify, PHP is an interpreted language, NOT a compiled one. 🙂

---

<div class="post-metadata">

### Author: ![k77](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@k77](https://forum.kirupa.com/u/k77)
#### Post date: [June 4, 2008, 11:26am UTC](https://forum.kirupa.com/t/making-a-xml-manager-in-php/262038/5 "2008-06-04T11:26:15Z")

</div>

[quote=ahmednuaman;2336267]Yes that’s right. It is one of it’s failings, well I guess compared to the speed of MSIL, but it means that if your site’s on ServerX (Windows) and it went down, you could then quickly move it to ServerY (Any OS (nearly)) and get it back up again.

PHP, though, can be very fast, especially if you use a PHP cache such as:  
[http://www.php.net/apc](http://www.php.net/apc)  
[http://eaccelerator.net/](http://eaccelerator.net/)  
[http://xcache.lighttpd.net/[/quote]](http://xcache.lighttpd.net/%5B/quote%5D)

```auto

<?xml version="1.0"?>
<images>
<image>
<pic>kitten.jpg</pic>
<caption>A picture of a kitten</caption>
<url>http://www.k77eel.com</url>
</image>
</images>

```

This is the XML that I want to parse. It wont load. This is my class.

```php

<?php
// HTML ETC
// LICENCE COPYRIGHT TO K77 ETC
class ImageList {
        var $parser;
        var $record;
        var $active_field = '';
        var $data_type;
        var $ends_data;
        var $data;
        
        function ImageList ($filename) {
            $this->parser = xml_parser_create();
            xml_set_object($this->parser, &$this);
            xml_set_element_handler($this->parser, 'start_element', 'end_element');
            xml_set_character_data_handler($this->parser, 'cdata');
            
            $this->data_type = array('pic' => 1,
                                     'caption' => 1,
                                     'url' => 1);
            $this->ends_data = array('image' => true);
            
            $saladin = join("", file($filename));
            xml_parse($this->parser, $saladin);
            xml_parser_free($this->parser);
    }
    
    function start_element ($khalid, $element, &$attributes) {
        $element = strtolower($element);
        if ($this->data_type[$element] != 0) {
            $this->active_field = $element;
        } else {
            $this->active_field = '';
        }
    }
    
    function end_element ($khalid, $element) {
        $element = strtolower($element);
        if ($this->ends_data[$element]) {
            $this->data[] = $this->data;
            $this->data = array();
        }
        $this->active_field = '';
    }
    
    function cdata ($khalid, $text) {
        if ($this->data_type[$this->active_field] === 2) {
            $this->data[$this->active_field][] = $text;
        } elseif ($this->data_type[$this->active_field] === 1) {
            $this->data[$this->active_field] .=$text;
        }            
    }
    
    function display() {
        echo '<table border="0">
';
        foreach ($this->data as $image) {
            echo '<tr>';
            $image = join(',', $image['image']);
            printf("<th>
                        <a href='%s'>%s</a>
                    </th>
                    <td>
                        %s
                    </td>
                 </tr>
",
                 $_SERVER['PHP_SELF'] . '?pic=' . $image['pic'],
                 $image['caption'],$image);
            echo "</tr>
";
        }
    }
    
    function show_image ($pic) {
        foreach ($this->data as $image) {
            if ($image['pic'] !== $pic) {
                continue;
            }
            
            $image = join(',', $image['image']);
            printf("<b>%s</b> by %s.<br>", $image['caption'], $image);
            printf("Picture %s<br>", $image['pic']);
            printf("URL: %s<p>
", $image['url']);            
        }
?>
<a href="<?= $_SERVER['PHP_SELF'] ?>">Back</a> to full list.</p>            
<?php
        }
    };
    
    $my_images = new ImageList("xml.xml");
    if ($_GET['pic']) {
        $my_images->show_image($_GET['pic']);
    } else {
        $my_library->display();
    }
?>

```

---

<div class="post-metadata">

### Author: ![k77](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@k77](https://forum.kirupa.com/u/k77)
#### Post date: [June 4, 2008, 7:22pm UTC](https://forum.kirupa.com/t/making-a-xml-manager-in-php/262038/6 "2008-06-04T19:22:31Z")

</div>

Its taking about an undefined function

```auto

Warning: join() [function.join]: Invalid arguments passed in /my/admincp.php on line 396

```

I don’t have a join function. My function is a method inside the function. PHP is not a language for record, its a scripting language

---

<div class="post-metadata">

### Author: ![k77](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@k77](https://forum.kirupa.com/u/k77)
#### Post date: [June 5, 2008, 3:53pm UTC](https://forum.kirupa.com/t/making-a-xml-manager-in-php/262038/7 "2008-06-05T15:53:50Z")

</div>

I don’t understand implode. Where would I place this?

according to PHP implode makes several variables to an indexed array and then to a string. Surely I want to use a string to make the call and not duck around with other siht.
