mod
netslr=567888
sisa=MOD(netslr,100)
bayar=netslr-sisa
dibulatkan ke atas bila sisa lebih dari 50
kurang=100-sisa
bayar=netslr+(sisa+kurang)
or
etslr=567888
sisa=MOD(netslr,100)
?sisa —> hasilnya 88
bayar=netslr-sisa
?bayar —> hasilnya 567800
atau
netslr=567888
sisa=MOD(netslr,100)
bayar=netslr+(100-sisa)
Fungsi string adalah fungsi yang mengolah kata atau huruf. Fungsi-fungsi tersebut sebagai berikut:
<?php
$str = "Is your name O'reilly?";
// Outputs: Is your name O\'reilly?
echo addslashes($str);
?><?php
// Contoh 1
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
// Contoh 2
$data = “foo:*:1023:1000::/home/foo:/bin/sh”;
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(“:”, $data);
echo $user; // foo
echo $pass; // *
?>
<?php
$str = "A 'quote' is <b>bold</b>";
// Outputs: A ‘quote’ is <b>bold</b>
echo htmlentities($str);
?>
<?php
$text = “\t\tThese are a few words
… “;
$trimmed = ltrim($text);
// $trimmed = “These are a few words
… “
$trimmed = ltrim($text, ” \t.”);
$trimmed = rtrim($text);
// $trimmed = "\t\tThese are a few words
..."
echo trim($text); // "These are a few words
..."
echo trim($text, " \t."); // "These are a few words
"
?>
<?php
$str = 'apple';
if (md5($str) === ‘1f3870be274f6c49b3e31a0c6728957f’) {
echo “Would you like a green or red apple?”;
exit;
}
?>
<?php
echo nl2br("foo isn't\n bar");
?>
Outputnya akan menjadi:
foo isn't<br />
bar
<?php
$email = 'user@Contoh.com';
$domain = strstr($email, '@');
echo $domain; // prints @Contoh.com
?><?php
// Provides: <body text='black'>
$bodytag = str_replace("%body%", "black", "<body text='%body%'>");
// Provides: Hll Wrld f PHP
$vowels = array(“a”, “e”, “i”, “o”, “u”, “A”, “E”, “I”, “O”, “U”);
$onlyconsonants = str_replace($vowels, “”, “Hello World of PHP”);
// Provides: You should eat pizza, beer, and ice cream every day
$phrase = “You should eat fruits, vegetables, and fiber every day.”;
$healthy = array(“fruits”, “vegetables”, “fiber”);
$yummy = array(“pizza”, “beer”, “ice cream”);
$newphrase = str_replace($healthy, $yummy, $phrase);
?>
<?php
$text = '
<p>Test paragraph.</p>
<!-- Comment -->
Other text';
echo strip_tags($text);
echo “\n\n——-\n”;
// allow <p>
echo strip_tags($text, ‘<p>’);
?>
Outputnya:
Test paragraph.
Other text ------- <p>Test paragraph.</p> Other text
<?php
$str = "Is your name O\'reilly?";
// Outputs: Is your name O’reilly?
echo stripslashes($str);
?>
<?php
$str = 'abcdef';
echo strlen($str); // 6
$str = ‘ ab cd ‘;
echo strlen($str); // 7
?>
<?php
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtolower($str);
echo $str; // Prints mary had a little lamb and she loved it so
?><?php
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtoupper($str);
echo $str; // Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
?><?php
$foo = 'hello world!';
$foo = ucfirst($foo); // Hello world!
$bar = ‘HELLO WORLD!’;
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>
<?php
$foo = 'hello world!';
$foo = ucwords($foo); // Hello World!
$bar = ‘HELLO WORLD!’;
$bar = ucwords($bar); // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>
<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");
echo $newtext;
?>