ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Something cool from wordpress,but what is it?

December 19, 2010 6:48am

Subscribe [5]
  • #1 / Dec 19, 2010 6:48am

    phpserver

    149 posts

    I have come across this code for storing theme options in wordpress and i would like to know what this format of storing stuff is to use it in my future projects.

    a:34:{s:15:"generalsettings";N;s:0:"";N;s:12:"color_scheme";s:0:"";s:9:"site_name";s:0:"";s:11:"custom_logo";s:0:"";s:10:"twitter_id";s:48:"also include facebook username:this is a comment";s:13:"header_teaser";s:10:"customtext";s:12:"teaser_style";s:0:"";s:13:"teaser_custom";s:0:"";s:13:"cufon_disable";N;s:18:"breadcrumb_disable";N;s:14:"analytics_code";s:0:"";s:8:"homepage";N;s:11:"teaser_text";s:0:"";s:13:"teaser_button";s:2:"26";s:16:"mainpage_content";s:0:"";s:19:"home_teaser_disable";N;s:14:"slider_disable";s:1:"1";s:12:"slider_speed";s:0:"";s:15:"homepage_slider";s:6:"custom";s:15:"slider_showcats";s:0:"";s:12:"slider_count";s:0:"";s:4:"blog";N;s:9:"blog_page";s:0:"";s:16:"blog_excludecats";s:0:"";s:21:"related_popular_posts";N;s:16:"social_bookmarks";N;s:12:"about_author";N;s:7:"sidebar";N;s:14:"footersettings";N;s:11:"footer_text";s:0:"";s:14:"footer_include";s:0:"";s:11:"navsettings";N;s:12:"show_hide_pg";s:0:"";}

    What is this format and where can i get more information about it?

  • #2 / Dec 19, 2010 7:19am

    phpserver

    149 posts

  • #3 / Dec 19, 2010 7:40am

    Sire

    109 posts

    Do you mean the json format?  Look at json_encode and json_decode
    http://php.net/manual/en/function.json-encode.php
    http://php.net/manual/en/function.json-decode.php

  • #4 / Dec 19, 2010 8:02am

    phpserver

    149 posts

    I was thinking there was more to it than the json but i have now figured it all out.

  • #5 / Dec 19, 2010 4:53pm

    moodh

    94 posts

    That kind of data is achieved by using serialize() and unseralize() on a simple array to store it in text format, it’s NOT JSON.
    This is JSON:
    {"bindings": [
    {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
          {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
          {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
      ]
    }

  • #6 / Dec 19, 2010 6:47pm

    phpserver

    149 posts

    I never said it was json,i was reacting to Sire encode and decode links.Curious:Does expression engine implement such a format:

    a:34:{s:15:"generalsettings";N;s:0:"";N;s:12:"color_scheme";.....
  • #7 / Dec 20, 2010 11:52am

    Joseph Wensley

    38 posts

    I never said it was json,i was reacting to Sire encode and decode links.Curious:Does expression engine implement such a format:

    a:34:{s:15:"generalsettings";N;s:0:"";N;s:12:"color_scheme";.....

    EE uses serialized data for reverse relationships and extension settings; CI uses it for session data stored in the DB.

  • #8 / Dec 20, 2010 12:48pm

    phpserver

    149 posts

    Is there a decent tutorial where i can learn more about this format?

  • #9 / Dec 20, 2010 12:58pm

    samitrimal

    32 posts

    i think its using

    serialize()

    function . may be it will help u

  • #10 / Dec 20, 2010 1:19pm

    phpserver

    149 posts

    It looks like it,but its amazing,i have been looking real hard for information on wp forums on it and nothing pops,nothing,zip.

  • #11 / Dec 20, 2010 1:37pm

    phpserver

    149 posts

  • #12 / Jan 03, 2011 10:51am

    InsiteFX

    6819 posts

    This is how CodeIgniter does it in the Session Class.

    // --------------------------------------------------------------------
    
    /**
     * Serialize an array
     *
     * This function first converts any slashes found in the array to a temporary
     * marker, so when it gets unserialized the slashes will be preserved
     *
     * @access    private
     * @param    array
     * @return    string
     */
    function _serialize($data)
    {
        if (is_array($data))
        {
            foreach ($data as $key => $val)
            {
                if (is_string($val))
                {
                    $data[$key] = str_replace('\\', '{{slash}}', $val);
                }
            }
        }
        else
        {
            if (is_string($data))
            {
                $data = str_replace('\\', '{{slash}}', $data);
            }
        }
    
        return serialize($data);
    }
    // --------------------------------------------------------------------
    
    /**
     * Unserialize
     *
     * This function unserializes a data string, then converts any
     * temporary slash markers back to actual slashes
     *
     * @access    private
     * @param    array
     * @return    string
     */
    function _unserialize($data)
    {
        $data = @unserialize(strip_slashes($data));
    
        if (is_array($data))
        {
            foreach ($data as $key => $val)
            {
                if (is_string($val))
                {
                    $data[$key] = str_replace('{{slash}}', '\\', $val);
                }
            }
    
            return $data;
        }
    
        return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data;
    }

    InsiteFX

  • #13 / Jan 14, 2011 3:04pm

    phpserver

    149 posts

    Wow,thanks.

  • #14 / Jan 24, 2011 12:27am

    Vheissu

    278 posts

    Pyrocms also does the same thing and serializes module options, etc. A few applications built on CI do it, including SiteManPro.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases