<?php
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
?>
<?php
if (!file_exists('folder/'.'1')) {
mkdir('folder/'.'1', 0777, true);
echo 'folder został stworzony';
}else{
echo "folder juz istnieje";
}
?>
<?php
$mystring = 'ten text chcę=a tego nie';
$first = strtok($mystring, '=');
echo $first.'<br><br><br>'; // ten text chcę
<?php
function GetBetween($var1="",$var2="",$pool){
$temp1 = strpos($pool,$var1)+strlen($var1);
$result = substr($pool,$temp1,strlen($pool));
$dd=strpos($result,$var2);
if($dd == 0){
$dd = strlen($result);
}
return substr($result,0,$dd);
}
//===============================================
$str ='chce wszystko od @to chce wyciagnąć@';
echo GetBetween('@','@',$str);//to chce wyciagnąć
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php
if (isset($_POST) && $_SERVER['REQUEST_METHOD'] == "POST") {
$sex = $_POST['sex'];
$check_sign = strlen($sex);
$pattern = $sex[$check_sign - 1];
if ($pattern == "a" || $pattern == "A") {
echo "kobieta";
}else {
echo "męzczyzna";
}
}
?>
<form action="" method="post">
<input type="text" name="sex" placeholder="Wpisz imie">
<input type="submit" value="sprawdz płeć" >
</form>
</body>
</html>
<?php
class RandomCodeGenerator {
/**
* rand code(integer or alphanumeric) by lenght
*
* @param int $length
* @return string|integer
*/
public static function generate($length = 4, $alphanumeric = false) {
if ($alphanumeric) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
} else {
$characters = '0123456789';
}
$characterLength = strlen($characters);
$randomcode = '';
for ($i = 0; $i < $length; $i++) {
$randomcode .= $characters[rand(0, $characterLength - 1)];
}
return $randomcode;
}
}
<?php
header('Location: ' . $_SERVER['HTTP_REFERER']);
?>
<?php
function rand_color() {
$r = str_pad(dechex(rand(0, 255)), 2, '0', STR_PAD_LEFT);
$g = str_pad(dechex(rand(0, 255)), 2, '0', STR_PAD_LEFT);
$b = str_pad(dechex(rand(0, 255)), 2, '0', STR_PAD_LEFT);
return '#'.$r.$g.$b;
}
echo '<div style="background: '.rand_color().';height:600px">treść</div>';