示例#1
0
function compareResult($string)
{
    $success = array();
    $result = array();
    $i = 1;
    while ($i <= 300) {
        $result = createRandom();
        foreach ($result as $k => $v) {
            //if a given random value matches the value in the same place in $string, add it to the $success array
            if ($v == $string[$k]) {
                $success[$k] = strtoupper($v);
            }
        }
        echo "<br>";
        echo "Generation " . $i . ": ";
        ksort($success);
        $j = 0;
        while ($j <= 30) {
            //$result = createRandom();
            if (!$success[$j]) {
                $success[$j] = "*";
                //originally I had this equal to createRandomLetter(), but the array was never in the right order!
            }
            ksort($success);
            $j++;
        }
        ksort($success);
        $happy = implode("", $success);
        foreach ($success as $s) {
            if ($s == "*") {
                echo createRandomLetter();
            } else {
                echo $s;
            }
        }
        //echo "<br>";
        //print_r($success);
        $i++;
        echo "<br><br>";
        if ($happy == "METHINKS A MORTAL DOTH APPROACH") {
            echo 'C:\\Windows\\System32>success';
            exit;
        }
    }
    return $success;
}
示例#2
0
#!/usr/bin/env php
<?php 
function createRandom($len, $alphabet)
{
    $alphabetSize = strlen($alphabet);
    $result = '';
    for ($i = 0; $i < $len; $i++) {
        $result .= $alphabet[rand(1, $alphabetSize) - 1];
    }
    return $result;
}
if (empty($argv[1])) {
    $len = 8;
} else {
    $len = $argv[1];
}
print createRandom($len, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
示例#3
0
     } 
     */
 }
 if ($fail == "false") {
     // only go to resizeImage if file exists
     if ($fileToUpload1 != "empty") {
         resizeImage(1000, 1000, $target_file1);
     }
     if ($fileToUpload2 != "empty") {
         resizeImage(1000, 1000, $target_file2);
     }
     if ($fileToUpload3 != "empty") {
         resizeImage(1000, 1000, $target_file3);
     }
     // This is where you would enter the posted fields into a database
     $tempKey = createRandom(10);
     $userKey = test_input($tempKey);
     //printf("UserKey is : %s.\n", $userKey);
     //status field defaults to "waiting"
     //$sql = "INSERT INTO ItemsForSale (itemname) VALUES ('$itemname')";
     $sql = "INSERT INTO ItemsForSale (itemname, description, price, city, state, category, \n     useremail, salephoto, salephotoB, salephotoC, userKey, vendor, vendorlink) VALUES ('{$itemname}', '{$description}', '{$price}', '{$city}', '{$state}', \n      '{$category}', '{$email}', '{$imageName1}', '{$imageName2}', '{$imageName3}', '{$userKey}', '{$vendor}', '{$vendorlink}')";
     mysqli_query($conn, $sql);
     // old way  queryMysql("INSERT INTO ItemsForSale (itemname, description, price, city, state, category,
     //  useremail, salephoto, salephotoB, salephotoC, userKey) VALUES ('$itemname', '$description', '$price', '$city', '$state',
     //  '$category', '$email', '$imageName1', '$imageName2', '$imageName3', '$userKey')");
     //need to get itemid to make image name with format itemid.jpg (itemid not available until INSERT done)
     //use the $userKey to get the itemid that was created when record was inserted
     $sql = "SELECT `itemid` FROM `ItemsForSale` WHERE `userKey` = '{$userKey}'";
     $result = mysqli_query($conn, $sql);
     // old way $result =  queryMysql("SELECT `itemid` FROM `ItemsForSale` WHERE `userKey` = '$userKey'");
     $row = mysqli_fetch_row($result);
示例#4
0
// String Function
</b><br><br>

<?php 
$myWord = 'This is Spartaaaa !';
function countWords()
{
    global $myWord;
    echo 'Just Count : ' . str_word_count($myWord);
    echo '<br> Array : ';
    print_r(str_word_count($myWord, 1));
    echo '<br> Associative Array : ';
    print_r(str_word_count($myWord, 2));
    echo '<br> Counting ! symbol also : ';
    print_r(str_word_count($myWord, 2, '!'));
}
countWords();
?>

<br><br><b>
// Create Random AlphaNum Code
</b><br><br>

<?php 
function createRandom()
{
    $charCollection = '5317908462poiuytrejhbc!&%#';
    echo str_shuffle($charCollection);
}
createRandom();