1. Halo Guest, pastikan Anda selalu menaati peraturan forum sebelum mengirimkan post atau thread baru.

[Help] Spinner text di php

Discussion in 'Pemrograman Web' started by teukualamsyah, Mar 28, 2018.

  1. Roy Jono

    Roy Jono Ads.id Starter

    Joined:
    Dec 26, 2017
    Messages:
    65
    Likes Received:
    1
    ane rada bingung neh..
    hadeeuhh...
     
  2. virli

    virli Newbie

    Joined:
    Jun 13, 2016
    Messages:
    7
    Likes Received:
    0
    Location:
    Cirebon
    coba ini gan
    PHP:
    <?php
    $title 
    get_the_title($post->ID);
    function 
    spinner($words) {
        return 
    preg_replace_callback(
            
    '/\{(((?>[^\{\{\}\}]+)|(?R))*)\}/x',
            function(
    $words) {
                
    $text  spinner($words[1]);
                
    $parts explode('|'$text);
                return 
    $parts[array_rand$parts )];
            },
            
    $words
        
    );
    }

    $title '{Allowed|I\'ts} .' $title .' {to|in order to|to be able to|for you to|to help}';
    echo 
    spinner($title);
     
  3. reival

    reival Ads.id Fan

    Joined:
    Aug 26, 2011
    Messages:
    122
    Likes Received:
    22
    Pertama bikin variable untuk kumpulan text yg mau di buat replace:
    PHP:
    $txt "{Welcome|Encouraged|Pleasant|Delightful|Allowed} {to|in order to|to be able to|for you to|to help} {my|my personal|my own|our|the} {blog|weblog|website|website|blog site|blog}, {in this|with this|on this|within this|in this particular} {time|period|moment|occasion|time period} {I'll|I will|I am going to|I'm going to|We'll} {show you|demonstrate|explain to you|teach you|provide you with} {about|regarding|concerning|with regards to|in relation to}";
    Terus buat function spinner:
    PHP:
    function spinner($txt){
    $f explode('}'$txt);
    foreach(
    $f as $g){
    $g explode('{'$g);
    foreach(
    $g as $gg){
    if(
    $gg){
    $h explode ('|'$gg);
    $h1 array_rand($h);
    $h2 $h[$h1];
    $h2str_replace(' , '', '$h2);
    $h3 .= str_replace(' . ''. '$h2);

         }
       }
     }
    return 
    "$h3 ";
    }
    Terus tampilin text:
    PHP:
    echo spinner($txt);

    Contoh fullnya:

    PHP:
    <?php
    $txt 
    "{Welcome|Encouraged|Pleasant|Delightful|Allowed} {to|in order to|to be able to|for you to|to help} {my|my personal|my own|our|the} {blog|weblog|website|website|blog site|blog}, {in this|with this|on this|within this|in this particular} {time|period|moment|occasion|time period} {I'll|I will|I am going to|I'm going to|We'll} {show you|demonstrate|explain to you|teach you|provide you with} {about|regarding|concerning|with regards to|in relation to}";


    function 
    spinner($txt){
    $f explode('}'$txt);
    foreach(
    $f as $g){
    $g explode('{'$g);
    foreach(
    $g as $gg){
    if(
    $gg){
    $h explode ('|'$gg);
    $h1 array_rand($h);
    $h2 $h[$h1];
    $h2str_replace(' , '', '$h2);
    $h3 .= str_replace(' . ''. '$h2);

         }
       }
     }
    return 
    "$h3 ";
    }


    ?>
    Hi <?=spinner($txt)?> Bla bla
    Agan pahamin aja dulu itu ane Bantu bikin codenya sesimple mungkin Dan enak dipahamin.
     
    Last edited: Jul 2, 2018

Share This Page