$String Help!

Discussion in 'PHP' started by WebEnterprise, Jun 6, 2011.

  1. #1
    Hello Guys, I need a little help with the below example, can someone simplify this for me?

    
    define("PRT11_WIDTH", 600);
    define("PRT11_HEIGHT", 365);
    define("PRT11_REGEXP", "/\[v1-1]/");
    define("PRT11_TARGET", "<div class=\"nanotabs\"><div id=\"ichi($string)\">");
    
    function PRT11_plugin_callback($match) {
    	$output = PRT11_TARGET;
    	$output = str_replace("###URL###", $match[1], $output);
    	return ($output);
    }
    
    function genRandomString() {
        $length = 5;
        $characters = ’0123456789abcdefghijklmnopqrstuvwxyz’;
        $string = ”;    
        for ($p = 0; $p < $length; $p++) {
            $string .= $characters[mt_rand(0, strlen($characters))];
        }
        return $string;
    }
    
    
    function PRT11_plugin($content) {
    	return preg_replace_callback(PRT11_REGEXP, 'PRT11_plugin_callback',
    $content);
    }
    
    add_filter('the_content', 'PRT11_plugin');
    add_filter('the_content_rss', 'PRT11_plugin');
    add_filter('comment_text', 'PRT11_plugin');
    add_filter('the_excerpt', 'PRT11_plugin');
    
    PHP:
    Basically this is a shortcode, [v1-1] will output

    <div class="nanotabs"><div id="ichi(RANDOM#Here)">
    HTML:
    I need a random # generated after id="ichi(HERE)"

    However I can't get it to work...Can someone help me here?

    Can This entire code be simplified?
     
    WebEnterprise, Jun 6, 2011 IP
  2. accounthub

    accounthub Greenhorn

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    
    define("PRT11_WIDTH", 600);
    define("PRT11_HEIGHT", 365);
    define("PRT11_REGEXP", "/\[v1-1]/");
    define("PRT11_TARGET", "<div class=\"nanotabs\"><div id=\"ichi'.time().'\">");
    
    function PRT11_plugin_callback($match) {
        $output = PRT11_TARGET;
        $output = str_replace("###URL###", $match[1], $output);
        return ($output);
    }
    
    function genRandomString() {
        $length = 5;
        $characters = ’0123456789abcdefghijklmnopqrstuvwxyz’;
        $string = ”;    
        for ($p = 0; $p < $length; $p++) {
            $string .= $characters[mt_rand(0, strlen($characters))];
        }
        return $string;
    }
    
    
    function PRT11_plugin($content) {
        return preg_replace_callback(PRT11_REGEXP, 'PRT11_plugin_callback',
    $content);
    }
    
    add_filter('the_content', 'PRT11_plugin');
    add_filter('the_content_rss', 'PRT11_plugin');
    add_filter('comment_text', 'PRT11_plugin');
    add_filter('the_excerpt', 'PRT11_plugin');
    
    
    Code (markup):
     
    accounthub, Jun 6, 2011 IP
  3. WebEnterprise

    WebEnterprise Active Member

    Messages:
    189
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    68
    #3
    This is what outputed :
    <div class="nanotabs"><div id="ichi'.time().'">
    HTML:
    ??? I dont understand where you got the '.time().' ???
     
    WebEnterprise, Jun 6, 2011 IP
  4. accounthub

    accounthub Greenhorn

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    time is a unix timestamp. you can create random numbers this way. I left out the double quotes
    define("PRT11_TARGET", "<div class=\"nanotabs\"><div id=\"ichi".time()."\">");
    Code (markup):
     
    accounthub, Jun 6, 2011 IP