Config Handler inserting erroneous quote

Gravatar samuellittley

  • Posts: 41
  • Topic Created: Thu Jan 19 17:34:24 2012 +0100
  • Topic Updated: Thu Jan 19 17:38:46 2012 +0100

I'm updating my recent links module to allow editing of the links. The links are all in one textarea, one per line, url and text separated by , The code i'm using to run it looks like http://ideone.com/IhWlb - the array printed at the end is what is passed to $config->set("recent_links",$links) The config handler is then putting a quote at the start of each text item like below, i can't work out why. It's also only putting the first link under recent_links - the rest end up in separate sections

recent_links:
  0:
    url: "http://twitter.com/ChrisTaylor_TF/statuses/153423521844953088"
    text: "\"Twitter"
0:
  1:
    url: "http://t.co/TQHj9dN0"
    text: "\"This is why I don't give you a job"
1:
  2:
    url: "http://twitter.com/newsycoambinator/statuses/157749990473732097"
    text: "\"Twitter"
2:
  3:
    url: "http://t.co/iUCM3gqf"
    text: "\"People wonder why I'm an atheist ..."
3:
  4:
    url: "http://news.ycombinator.com"
    text: "\"Hacker News"
4:
  5:
    url: "http://www.davidkendal.net"
    text: "\"davidkendal.net"
5:
  6:
    url: "http://twitter.com/phazonoverload/statuses/159373703422029824"
    text: "\"Twitter"
6:
  7:
    url: "http://twitter.com/#!/herpderpedia"
    text: "\"@herpderpedia"
7:
  8:
    url: "http://t.co/rogAAD7e"
    text: "@LordJawsh."

The full code is:


            public function admin_recent_links_settings($admin)
            {
                $config = Config::current();
                if(empty($_POST)) {
                    $links = $config->recent_links;
                    $linkstext = "";
                    foreach ($links as $link) {
                        $linkstext .= $link['url'].",".$link['text']."\n";
                    }
                    return $admin->display("recent_links_settings",array("linkstext" => $linkstext));
                }
                if (isset($_POST['show_recent_links'])) {
                    $showlinks = True;
                } else {
                    $showlinks = False;
                }
                if (isset($_POST['recent_links_reverse_order'])) {
                    $reverse = True;
                } else {
                    $reverse = False;
                }
                $lines = explode("\n", $_POST['recent_links']);
                $lines = array_filter($lines,'trim');
                $links = array();
                foreach ($lines as $line) {
                    $phrases = explode(",",$line);
                    $href = trim(array_shift($phrases));
                    $text = "";
                    while ($phrase = array_shift($phrases)) {
                        $text .= $phrase;
                    }
                    $link = array("url" => $href, "text" => $text);
                    $links[] = $link;
                }
                if (($config->set("recent_links_title", $_POST['recent_links_title'])) && ($config->set("recent_links_display_count", $_POST['recent_links_di$
                Flash::notice(__("Settings updated."), "/admin/?action=recent_links_settings");
                }
            }

Gravatar jack

how are you printing the array? var_dump?

Gravatar samuellittley

The code sample on ideone uses print_r The excerpt above is copied and pasted from my config.yaml.php