Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
phpfiddle / fiddle_023131.php
Created April 2, 2018 21:12
[ Posted by Kapry ] php pdo script ejemplo 1
<?php
//Autor: Walter Sanchez
//Fecha: 02 abril 2018
class html{
private $script=null;
public function cabeza($tituloPagina="Sin Titulo"){
$inicio = '<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <title>'.$tituloPagina.'</title>';
$cierreHead = '</head>';
// compruebo que la propiedad script no sea nula es decir que se haya seteado.
<?php
// Simple Encryption #1 - Alternating Split
/*
For building the encrypted string:
Take every 2nd char from the string, then the other chars, that are not every 2nd char, and concat them as new String.
Do this n times!
*/
function encrypt($text, $n) {
for($i=0;$i<$n;$i++){
@phpfiddle
phpfiddle / fiddle_029304.php
Created April 2, 2018 18:03
[ Posted by Michaeljpitz ] Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore (&#039;_&#039;).
<?php
$str = "abcde";
$a=str_split($str,2);
$nb = count($a);
if(strlen($a[$nb-1])<2) $a[$nb-1].="_";
var_dump($a);
?>
@phpfiddle
phpfiddle / fiddle_080222.php
Created March 30, 2018 05:37
[ Posted by Shubham Nitin Joshi ] This is login file
<?php
include("config.php");
session_start();
$error='';
// $_SESSION['testcomplete'] = 'yes';
if($_SERVER["REQUEST_METHOD"] == "POST") {
@phpfiddle
phpfiddle / fiddle_026210.php
Created March 29, 2018 09:19
[ Posted by Michaeljpitz ] Multiples of 3 or 5 PHP Codewars
<?php
// Multiples of 3 or 5 PHP
// If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
// Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.
function solution($number) {
$tot = 0;
for ($i = 3; $i < $number; $i++) if ($i % 3 === 0 || $i % 5 === 0) $tot += $i;
return $tot;
}
echo solution(10);//23
<?php
$rows = ''; $attr = 'class="table"';$rn = PHP_EOL;
for($i=0; $i<10;$i++)
{$rows .= '<tr>'.$rn;
for($j=0; $j<10;$j++)
$rows .= sprintf("\t\t".'<t%1$s>'.$i.'.'.$j.'</t%1$s>'.$rn, (($i==0||$j==0)?'h':'d'));
$rows .= '</tr>'.$rn; }
echo $table = sprintf('<table %s>%s</table>',$attr, $rows )
?>
<style>.table, .table tr, .table td {border-collapse:collapse; border:1px solid black;} .table td, .table, th{padding:3px;}</style>
@phpfiddle
phpfiddle / fiddle_040408.php
Created March 25, 2018 12:02
[ Posted by Michaeljpitz ] function stray($arr)
<?php
function stray($arr)
{
$arr = array_count_values($arr);
foreach($arr as $key => $value){
if($value===1)return $key;
}
}
var_dump(stray([1,2,1,1]));
<?php
header('content-type: text/plain');
$data = '1000$
Lorem ipsum dolor sit amet,
consectetur adipiscing elit, sed do eiusmod tempor incididunt.$
1001$
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.$';
@phpfiddle
phpfiddle / fiddle_021414.php
Created March 19, 2018 10:33
[ Posted by Sil Faber ] Opdracht 11
<?php
$n = 6;
$teller = 1;
for($i = 1; $i < $n; $i++) {
$teller = $teller * $i;
echo"$teller <br>";
}
echo"5 faculteit is $teller <br>";
?>
@phpfiddle
phpfiddle / fiddle_029760.php
Created March 18, 2018 23:23
[ Posted by Adomas1237 ] cascascasc
<?php
?>