Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

https://pt.stackoverflow.com/q/351747/101

php

<?php
echo true + "texto";

//https://pt.stackoverflow.com/q/351747/101

pascal triangle

php

<?php 
function binomialCoeff($n, $k) 
{ 
    $res = 1; 
    if ($k > $n - $k) 
    $k = $n - $k; 
    for ($i = 0; $i < $k; ++$i) 
    { 
        $res *= ($n - $i); 
        $res /= ($i + 1); 
    } 
return $res; 
} 
{ 
    
    for ($line = 0; $line < $n; $line++) 
    { 
        // Every line has number of  
        // integers equal to line  
        // number 
        for ($i = 0; $i <= $line; $i++) 
                echo "".binomialCoeff($line, $i)." "; 
                  
        echo "\n"; 
    } 
} 
  $n=7; 
printPascal($n); 
  ?> 

412412

php

<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
  /**
 * Read and parse text files
 */
class Parser
{
    private $file;
    public function setFile(string $f) {
        $this->file = $f;
    }
    public function getFile() {
        return $this->file;
    }
    public function getContent() {
        $i = fopen($this->file, 'r');
        $output = "";
        $data = null;
        while (($data = fgets($i)) !== false) {
            $output += $data;
        }
        return $output;
    }
    public function getContentWithoutEmptyLines() {
        $i = fopen($this->file, 'r');
        $output = "";
        $data = null;
        while (($data = fgets($i)) !== false) {
            if (trim($data) !== '') {
                $output += $data;
            }
        }
        return $output;
    }
    public function saveContent(string $content) {
        $o = fopen($this->file, 'w');
        for ($i = 0; $i < strlen($content); $i += 1) {
            fwrite($o, $content[$i]);
        }
    }
}
  
?>
</body>
</html>

Program 7

php

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="refresh" content="1"/>
<style>
p {
color:white;
font-size:90px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
body{background-color:black;}
</style>
<p> 
<?php echo date(" \n server\n h: i : s A  \n ");?> 
</p>
</head>

Program 6

php

<?php

print "<h3> REFRESH PAGE </h3>";

$name="counter.txt";

$file = fopen($name,"r");

$hits= fscanf($file,"%d");

fclose($file);


$hits[0]++;

$file = fopen($name,"w");

fprintf($file,"%d",$hits[0]);

fclose($file);


print "\n Total number of views: ".$hits[0];

?>

stats

php

<?php
 $liczby=[1,11,27,37,9,49];
       echo "Twoje liczby: ";
      foreach($liczby as $shot){
          echo $shot." ";
      }
$liczbaWygranych =0;
$maxWin=0;
$stats=[];
for($j=0;$j<49;$j++) {
    $stats[]=0;
}
 for($i=0;$i<10;$i++) {
 $trafienia = 0;
 $wylosowaneLiczby=[rand(1,49)];
 while(count($wylosowaneLiczby)<6) {
     $nowaLiczba=rand(1,49);
     if(!in_array($nowaLiczba,$wylosowaneLiczby)) {
         $wylosowaneLiczby[]=$nowaLiczba;
     }
 }

      echo PHP_EOL."Wylosowane liczby: ";
      foreach($wylosowaneLiczby as $los){
          echo $los." ";
          $stats[$los-1]++;
      }
      foreach($liczby as $liczba) {
          if(in_array($liczba,$wylosowaneLiczby)) {
          $trafienia++;
          }
      }
 echo PHP_EOL."Liczba trafień: $trafienia".PHP_EOL;
 if($trafienia>2) {
     $liczbaWygranych++;
     if($trafienia>$maxWin) {
         $maxWin=$trafienia;
     }
 }
}
echo PHP_EOL."Wygrane: $liczbaWygranych";
if($maxWin>0) {
    echo PHP_EOL."Największa wygrana: $maxWin";
}
echo PHP_EOL."Statystyki:".PHP_EOL;
$counter = 1;
foreach($stats as $stat) {
    echo "$counter = $stat".PHP_EOL;
    $counter++;
}
?>

why_json_encode

php

<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
    $a = json_decode(json_encode(["a"=>["b"=>1]],JSON_FORCE_OBJECT));
    print_r($a);
    
    $b=(object)["a"=>["b"=>1]];
    print_r($b);
?>
</body>
</html>

Execute PHP Online

php

<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
    <form action="PHP_SELF" method="POST">
        <input type="text" name="email">
        
    </form>
<?php
   $a=$_POST["email"];
   if(!isset($a))
        echo "Email cannot be empty";
?>
</body>
</html>

ritul code

php

<?php

$array      = array(10, 22, 28, 29, 30, 40);
$importVal  = 54;
$sumOf      = array(54);
    
    
    foreach($array as $arrayFrist){
        $tempVal = $arrayFrist;    
        foreach($array as $arrayLast){
            if($tempVal != $arrayLast){
                $total = $arrayLast + $tempVal;
                if(!in_array($total,$sumOf)){
                    $sumOf[] = $total;        
                }
                
            }
        }
    }
    rsort($sumOf);
    $result = array_search($importVal,$sumOf);
    //echo $result;
    print_r($sumOf);
    
    if($result != 0){
        $firstEvelementKey  = $result - 1;
        $lastEvelementKey   = $result + 1;
        
        $firstDiff = $firstEvelementKey -$result;
        $lastDiff  = $result - $lastEvelementKey;
        
        if($firstDiff > $lastDiff){
            echo $sumOf[$firstEvelementKey];
        }else{
            echo $sumOf[$lastEvelementKey];
        }
        
    }
?>

Execute PHP Online

php

<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
   echo "<h1>Hello, PHP!</h1>\n";
?>
</body>
</html>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.