Saturday, May 20, 2017

fread

<?php
$file_reader = fopen("sample_text.txt", "r");
$content = fread($file_reader, 4);
echo $content;
?>
Output:
This

mb_substr

<?php
if (ini_get("mbstring.func_overload") & 2 != 0) {
    echo "ini_get(\"mbstring.func_overload\")" . "<br/>";
}
if (function_exists('mb_substr')) {
 echo "mb_substr exists";
}
?>

File reading

<?php
$file_reader = fopen("sample_text.txt", "r");
while(!feof($file_reader)) {
 echo fgets($file_reader) . "<br/>";
}
?>
sample_text.txt:
This is 
php 
file reading example
Output:
This is 
php 
file reading example

Count

<?php
$color = array("blue", "red", "green", array("light gray", "dark gray"), "yellow" => array("lemon", "normal"));
echo count($color) . "<br/>";
echo count($color, 1);
?>
Output:
5
9

Saturday, May 6, 2017

explode

<?php
$colorStr = "blue:red:green:yellow";
$colors = explode(":", $colorStr, 3);
var_dump($colors);
$colors = explode(":", $colorStr, 4);
echo "<br/>";
var_dump($colors);
?>
Output:
array(3) { [0]=> string(4) "blue" [1]=> string(3) "red" [2]=> string(12) "green:yellow" } 
array(4) { [0]=> string(4) "blue" [1]=> string(3) "red" [2]=> string(5) "green" [3]=> string(6) "yellow" }

here docs

$x = <<<THE_END PHP stands for "PHP: Hypertext Preprocessor". The acronym "PHP" is therefore, usually referre...