Wat heb jij vandaag geprogrammeerd? 2.0

Gestart doorNielsba792 reacties10.961 weergaven

793 berichten · pagina 4 van 53

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12



protected function isBetween($time = array()) {
return (
(int)
date("Hi") >= (int) $time[0] && (int) date("Hi") <= (int) $time[1]
);
}


public function getLesuur() {
var_dump($this->isBetween(array(500, 2020)));
}

emo
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Een nieuwe zoekmachine op Relisten. Is nog niet live tho.
0
Berichten
4.213
Reputatie
0
Punten
0,02
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]

[COLOR= #007700]function[/COLOR] checkform[COLOR= #007700]()
{[/COLOR]
    [COLOR= #FF8000]//Maak van de POST vaste waardes[/COLOR]
    [COLOR= #0000BB]$getal1[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]getal1[/COLOR][COLOR= #007700]];[/COLOR]
    [COLOR= #0000BB]$getal2[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]getal2[/COLOR][COLOR= #007700]];[/COLOR]
    
    [COLOR= #FF8000]//Controleer of het wel nummers zijn[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](![/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]/^[0-9]*$/[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$getal1[/COLOR][COLOR= #007700]) && ![/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]/^[0-9]*$/[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$getal2[/COLOR][COLOR= #007700])) {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Dat zijn geen getallen!"[/COLOR][COLOR= #007700];
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$uitkomst[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/sqrt"]sqrt[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$getal1[/COLOR] [COLOR= #007700]*[/COLOR] [COLOR= #0000BB]$getal1[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$getal2[/COLOR] [COLOR= #007700]*[/COLOR] [COLOR= #0000BB]$getal2[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$uitkomst[/COLOR][COLOR= #007700];
    }
}[/COLOR]
                    
checkform[COLOR= #007700]();[/COLOR]
?>
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Robinkoch schreef:
[COLOR= #0000BB]<?php[/COLOR]

[COLOR= #007700]function[/COLOR] checkform[COLOR= #007700]()
{[/COLOR]
    [COLOR= #FF8000]//Maak van de POST vaste waardes[/COLOR]
    [COLOR= #0000BB]$getal1[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]getal1[/COLOR][COLOR= #007700]];[/COLOR]
    [COLOR= #0000BB]$getal2[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]getal2[/COLOR][COLOR= #007700]];[/COLOR]
    
    [COLOR= #FF8000]//Controleer of het wel nummers zijn[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](![/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]/^[0-9]*$/[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$getal1[/COLOR][COLOR= #007700]) && ![/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]/^[0-9]*$/[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$getal2[/COLOR][COLOR= #007700])) {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Dat zijn geen getallen!"[/COLOR][COLOR= #007700];
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$uitkomst[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/sqrt"]sqrt[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$getal1[/COLOR] [COLOR= #007700]*[/COLOR] [COLOR= #0000BB]$getal1[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$getal2[/COLOR] [COLOR= #007700]*[/COLOR] [COLOR= #0000BB]$getal2[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$uitkomst[/COLOR][COLOR= #007700];
    }
}[/COLOR]
                    
checkform[COLOR= #007700]();[/COLOR]
?>
Gefeliciteerd, je hebt zojuist het wiel opnieuw uitgevonden biggrin.
0
Berichten
6.144
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
@Robinkoch waarom die preg match op regel 10? Voldoet [func]is_numeric[/func] of [func]ctype_digit[/func] niet?
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Jponsen schreef:
@Robinkoch waarom die preg match op regel 10? Voldoet [func]is_numeric[/func] of [func]ctype_digit[/func] niet?
Of deze twee wielen. ^
0
Berichten
4.213
Reputatie
0
Punten
0,02
Lid sinds
Laatst gezien
Jessee schreef:
Eerdere citaten tonen
Robinkoch schreef:
[COLOR= #0000BB]<?php[/COLOR]

[COLOR= #007700]function[/COLOR] checkform[COLOR= #007700]()
{[/COLOR]
    [COLOR= #FF8000]//Maak van de POST vaste waardes[/COLOR]
    [COLOR= #0000BB]$getal1[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]getal1[/COLOR][COLOR= #007700]];[/COLOR]
    [COLOR= #0000BB]$getal2[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]getal2[/COLOR][COLOR= #007700]];[/COLOR]
    
    [COLOR= #FF8000]//Controleer of het wel nummers zijn[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](![/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]/^[0-9]*$/[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$getal1[/COLOR][COLOR= #007700]) && ![/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]/^[0-9]*$/[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$getal2[/COLOR][COLOR= #007700])) {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Dat zijn geen getallen!"[/COLOR][COLOR= #007700];
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$uitkomst[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/sqrt"]sqrt[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$getal1[/COLOR] [COLOR= #007700]*[/COLOR] [COLOR= #0000BB]$getal1[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$getal2[/COLOR] [COLOR= #007700]*[/COLOR] [COLOR= #0000BB]$getal2[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$uitkomst[/COLOR][COLOR= #007700];
    }
}[/COLOR]
                    
checkform[COLOR= #007700]();[/COLOR]
?>
Gefeliciteerd, je hebt zojuist het wiel opnieuw uitgevonden biggrin.

Dit moest zo voor een school opdrachtemoemo
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Afbeelding
Afbeelding
Afbeelding
Afbeelding
pompompompom
toevoeging op 10 juni 2015, 17:54:59:
Afbeelding

De school rooster app maar geen gebruik van JSON en ik heb geen idee hoe die de data krijgt (ik krijg allemal 302 document removed errors in WireShark). Dus heb ik me eigen "API" gemaakt.

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

$cacheFile = "./cache/data.json";
header(Cache-Control: no-cache, must-revalidate);
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT);
header(Content-type: application/json);

clearstatcache();
require_once("./json.php");
$rooster = new rocRooster("x", "x", "x");
if(time() - filemtime($cacheFile) >= 7200) {
file_put_contents($cacheFile, $rooster->getCurrentLes());
}


$data = json_decode(file_get_contents($cacheFile));

$data["currentHour"] = $rooster->getLesuur();

echo json_encode($data);

toevoeging op 11 juni 2015, 20:09:19:
niet echt iets productief:
Afbeelding
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Character arithmetic werkt. Dat betekent dat je nu shit als dit kan doen:

x = Hoi

writeln(x[0] + 1)


Dit geeft [c]I[/c].
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Raoul schreef:
Character arithmetic werkt. Dat betekent dat je nu shit als dit kan doen:
x = Hoi

writeln(x[0] + 1)


Dit geeft [c]I[/c].

Hoe kom je bij i dan?

0 is toch H?

toevoeging op 12 juni 2015, 21:53:31:
Aaah ik weet het al (ACSII)
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
inderdaad, ascii
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Raoul schreef:
inderdaad, ascii
Alleen wanneer gebruik je dit nou? Net zoals bitwise snap ik niet wanneer je zoiets nou gebruikt
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54



abstract class Animal {
public $name, $age;

public static $animals = 0;

public function __construct() {
self::$animals++;
}
}


interface AnimalIF {
public function setName($name);
public function setAge($age);
public function sayName();
public function sayAge();
}


final class Cat extends Animal implements AnimalIF {
public function sayName() {
echo "naam is: {$this->name}
"
;
}


public function sayAge() {
echo "leeftijd is: {$this->age}
"
;
}


public function setName($name) {
$this->name = $name;
}


public function setAge($age) {
$this->age = $age;
}


public function __construct($name, $age) {
$this->setName($name);
$this->setAge($age);
}


public function __destruct() {
parent::__construct();
echo "There are " . (string) parent::$animals . " total animals.
"
;
}

}


$a = [new Cat("Wollie", 19), new Cat("Jesse", 22)];

foreach($a as $b) {
$b->sayName();
$b->sayAge();
}


Codeblok (voorbeeld.php):

1
2
3
4
5
6

naam is: Wollie
leeftijd is: 19
naam is: Jesse
leeftijd is: 22
There are 1 total animals.
There are 2 total animals.
biggrin
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Codeblok (voorbeeld.php):

1
2
3
4
5
6

naam is: Wollie
leeftijd is: 19
naam is: Jesse
leeftijd is: 22
There are 1 total animals.
There are 2 total animals.
biggrin
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren