Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
22 posts Page 3 of 3
Getting some random chars:

Code: Select all
// Returns random char from regular non-UTF8 latin set
<cms:call 'random_char'  />

// Returns '+' or '-'
<cms:call 'random_sign' />

// Returns a single digit from '0' to '9'
<cms:call 'random_digit' />


Code: Select all
<cms:ignore>

    //  1. random_char
    //  2. random_sign
    //  3. random_digit

</cms:ignore>
<cms:func 'random_char' set='abcdefghijklmnopqrstuvwxyz0123456789/*-+()|\#$%^&@[]{};' ><cms:ignore>

        // Returns random char from regular non-UTF8 latin set

        // Sample to call this snippet:
        // <cms:call 'random_char' />
        // <cms:call 'random_char' set='abc' />

    </cms:ignore>
    <cms:php>
        global $FUNCS, $CTX;
        $set = $CTX->get('set');
        if( $set!='' ){
            // string substr ( string $string , int $start [, int $length ] )
            // Returns the portion of string specified by the start and length parameters.
            echo substr( $set, rand(0, strlen($set)-1), 1);
        }
    </cms:php>

</cms:func>

<cms:func 'random_sign' ><cms:ignore>

        // Returns '+' or '-'

        // Sample to call this snippet:
        // <cms:call 'random_sign' />

    </cms:ignore>
    <cms:call 'random_char' set='+-' />
</cms:func>

<cms:func 'random_digit' ><cms:ignore>

        // Returns a single digit from '0' to '9'

        // Sample to call this snippet:
        // <cms:call 'random_digit' />

    </cms:ignore>
    <cms:call 'random_char' set='0123456789' />
</cms:func>

active topics, google
Free support is never free.. Donate!
Feedback solicited: [NEW] Couch Constructor
Full list of functions will be listed and updated (and new added) in a non-public Github repo. Contact me if you need something.
active topics, google
Free support is never free.. Donate!
Feedback solicited: [NEW] Couch Constructor
22 posts Page 3 of 3

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 1 guest