Tuesday, 7 June 2016

fflush

18.18. Flushing Output to a File

18.18.1. Problem
You want to force all buffered data to be written to a filehandle.

18.18.2. Solution
Use fflush( ):

    fwrite($fh,'There are twelve pumpkins in my house.');
    fflush($fh);

This ensures that "There are twelve pumpkins in my house." is written to $fh.

18.18.3. Discussion
To be more efficient, system I/O libraries generally don't write something to a file when you tell them to. Instead, they batch the writes together in a buffer and save all of them to disk at the same time. Using fflush( ) forces anything pending in the write buffer to be actually written to disk.
Flushing output can be particularly helpful when generating an access or activity log. Calling fflush( ) after each message to log file makes sure that any person or program monitoring the log file sees the message as soon as possible.

18.18.4. See Also
Documentation on fflush( ) at http://www.php.net/fflush.

Friday, 3 June 2016

Questions: File functions

What is the output of following code?
<?php
$name = 'fpassthru.txt';

$str = <<<EOF
FOO
BAR
BAZ
EOF;

$fp = fopen($name, 'w');
fwrite($fp, $str);
fclose($fp);

$fp = fopen($name, 'r');
fgets($fp);
fpassthru($fp);
fclose($fp);
?>

a) FOO BAR
b) BAR BAZ
c) FOO BAZ
d) BAR FOO

Wednesday, 4 May 2016

INI configuration (SIAPS SERVER)

allow_url_fopen: 1
allow_url_include: 0
always_populate_raw_post_data: 1
arg_separator.input: ;&
arg_separator.output: &
asp_tags:
assert.active: 1
assert.bail:
assert.callback: 0
assert.quiet_eval: 0
assert.warning: 1
auto_append_file:
auto_detect_line_endings:
auto_globals_jit: 1
auto_prepend_file:
bcmath.scale: 0
browscap: extra/browscap.ini
curl.cainfo:
date.default_latitude: 31.7667
date.default_longitude: 35.2333
date.sunrise_zenith: 90.583333
date.sunset_zenith: 90.583333
date.timezone: UTC
default_charset:
default_mimetype: text/html
default_socket_timeout: 60
disable_classes:
disable_functions:
display_errors: 1
display_startup_errors:
doc_root:
docref_ext: .html
docref_root: /phpmanual/
enable_dl: 1
enable_post_data_reading: 1
engine: 1
error_append_string:
error_log: error_log
error_prepend_string:
error_reporting: 22519
exit_on_timeout: 0
expose_php: 1
extension_dir: /usr/local/lib/php/extensions/no-debug-non-zts-20100525
file_uploads: 1
filter.default: unsafe_raw
filter.default_flags:
from: john@doe.com
gd.jpeg_ignore_warning: 0
highlight.comment: #FF9900
highlight.default: #0000BB
highlight.html: #000000
highlight.keyword: #007700
highlight.string: #DD0000
html_errors:
iconv.input_encoding: ISO-8859-1
iconv.internal_encoding: ISO-8859-1
iconv.output_encoding: ISO-8859-1
ignore_repeated_errors:
ignore_repeated_source:
ignore_user_abort: 0
implicit_flush:
include_path: .:/usr/lib/php:/usr/local/lib/php
intl.default_locale:
intl.error_level: 0
last_modified: 0
log_errors: 1
log_errors_max_len: 1024
mail.add_x_header: 0
mail.force_extra_parameters:
mail.log:
max_execution_time: 60
max_file_uploads: 20
max_input_nesting_level: 64
max_input_time: 60
max_input_vars: 1000
mbstring.detect_order: auto
mbstring.encoding_translation:
mbstring.func_overload: 0
mbstring.http_input: auto
mbstring.http_output: SJIS
mbstring.http_output_conv_mimetypes: ^(text/|application/xhtml\+xml)
mbstring.internal_encoding: EUC-JP
mbstring.language: neutral
mbstring.strict_detection: 0
mbstring.substitute_character:
mcrypt.algorithms_dir:
mcrypt.modes_dir:
memory_limit: 128M
mysql.allow_local_infile: 1
mysql.allow_persistent: 1
mysql.connect_timeout: 60
mysql.default_host:
mysql.default_password:
mysql.default_port:
mysql.default_socket: /var/lib/mysql/mysql.sock
mysql.default_user:
mysql.max_links: -1
mysql.max_persistent: -1
mysql.trace_mode:
mysqli.allow_local_infile: 1
mysqli.allow_persistent: 1
mysqli.default_host:
mysqli.default_port: 3306
mysqli.default_pw:
mysqli.default_socket: /var/lib/mysql/mysql.sock
mysqli.default_user:
mysqli.max_links: -1
mysqli.max_persistent: -1
mysqli.reconnect: 0
mysqlnd.collect_memory_statistics: 0
mysqlnd.collect_statistics: 1
mysqlnd.debug:
mysqlnd.log_mask: 0
mysqlnd.mempool_default_size: 16000
mysqlnd.net_cmd_buffer_size: 4096
mysqlnd.net_read_buffer_size: 32768
mysqlnd.net_read_timeout: 31536000
opcache.blacklist_filename:
opcache.consistency_checks: 0
opcache.dups_fix: 0
opcache.enable: 1
opcache.enable_cli: 0
opcache.enable_file_override: 0
opcache.error_log:
opcache.fast_shutdown: 0
opcache.file_update_protection: 2
opcache.force_restart_timeout: 180
opcache.inherited_hack: 1
opcache.interned_strings_buffer: 4
opcache.load_comments: 1
opcache.log_verbosity_level: 1
opcache.max_accelerated_files: 2000
opcache.max_file_size: 0
opcache.max_wasted_percentage: 5
opcache.memory_consumption: 64
opcache.optimization_level: 0xFFFFFFFF
opcache.preferred_memory_model:
opcache.protect_memory: 0
opcache.restrict_api:
opcache.revalidate_freq: 2
opcache.revalidate_path: 0
opcache.save_comments: 1
opcache.use_cwd: 1
opcache.validate_timestamps: 1
open_basedir:
output_buffering:
output_handler:
pcre.backtrack_limit: 1000000
pcre.recursion_limit: 100000
pdo_mysql.default_socket: /var/lib/mysql/mysql.sock
phar.cache_list:
phar.readonly: 1
phar.require_hash: 1
phpd: 1
phpd.t: 1
post_max_size: 50M
precision: 12
realpath_cache_size: 16K
realpath_cache_ttl: 120
register_argc_argv: 1
report_memleaks: 1
report_zend_debug: 1
request_order:
sendmail_from: me@localhost.com
sendmail_path: /usr/sbin/sendmail -t -i
serialize_precision: 100
session.auto_start: 0
session.cache_expire: 180
session.cache_limiter: nocache
session.cookie_domain:
session.cookie_httponly: 1
session.cookie_lifetime: 0
session.cookie_path: /
session.cookie_secure:
session.entropy_file:
session.entropy_length: 0
session.gc_divisor: 100
session.gc_maxlifetime: 1440
session.gc_probability: 1
session.hash_bits_per_character: 4
session.hash_function: 0
session.name: PHPSESSID
session.referer_check:
session.save_handler: files
session.save_path: /tmp
session.serialize_handler: php
session.upload_progress.cleanup: 1
session.upload_progress.enabled: 1
session.upload_progress.freq: 1%
session.upload_progress.min_freq: 1
session.upload_progress.name: PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefix: upload_progress_
session.use_cookies: 1
session.use_only_cookies: 1
session.use_trans_sid: 0
short_open_tag: 1
SMTP: localhost
smtp_port: 25
soap.wsdl_cache: 1
soap.wsdl_cache_dir: /tmp
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
sourceguardian.restrict_unencoded: 0
sql.safe_mode:
sqlite3.extension_dir:
tidy.clean_output: 0
tidy.default_config:
track_errors:
unserialize_callback_func:
upload_max_filesize: 50M
upload_tmp_dir:
url_rewriter.tags: a=href,area=href,frame=src,input=src,form=,fieldset=
user_agent: PHP
user_dir:
user_ini.cache_ttl: 300
user_ini.filename: .user.ini
variables_order: EGPCS
xbithack: 0
xmlrpc_error_number: 0
xmlrpc_errors: 0
xsl.security_prefs: 44
zend.detect_unicode: 1
zend.enable_gc: 1
zend.multibyte: 0
zend.script_encoding:
zend_loader.disable_licensing: 0
zend_loader.enable: 1
zend_loader.max_alloca: 2048
zend_loader.obfuscation_level_support: 0
zlib.output_compression:
zlib.output_compression_level: -1
zlib.output_handler:

Tuesday, 3 May 2016

সাব প্যাটার্ন বাদ দেওয়া এটা দ্বারা ?:

Remove subpattern from array $matches

আগে
Array
(
    [0] => xxxxzzzz
    [1] => xxxx   // remove this by ?: 
    [2] => zzzz
)
 
$str = "xxxxzzzz";
preg_match("/(x+)(z+)/",  $str, $matches);
print_r($matches); 

 
পরে 
Array
(
    [0] => xxxxzzzz
    [1] => zzzz
)

Monday, 2 May 2016

strtok

strtok বিভিন্ন ধরনের দেলিমেতের থাকে এমন স্ট্রিং কে টোকেন হিসাবে রিটার্ন করে।  repeated delimiter থাকলে প্রতি একবার রান করলে একটা টোকেন স্ট্রিং রিটার্ন করে, এভাবে পর পর রান করলে পরবার একটা করে রিটার্ন পাওয়া যাবে সংশ্লিষ্ট ওই delimiter জন্য। সুধু প্রথমবার স্ট্রিং দিতে হই, তারপর শুধু delimiter token দিলেই হয়। প্রতি executioner পর এটা কারেন্ট position ধরে রাখে।

var_dump(strtok('a1/a2/a3/a4', '/')); //a1
var_dump(strtok('/')); // a2
var_dump(strtok('/')); // a3
var_dump(strtok('/')); // a4
var_dump(strtok('/')); // bool(false) , at 5th execution

string(2) "a1"
string(2) "a2"
string(2) "a3"
string(2) "a4"
bool(false)


<?php
$string 
"This is\tan example\nstring";/* Use tab and newline as tokenizing characters as well  */$tok strtok($string" \n\t");

while (
$tok !== false) {
    echo 
"Word=$tok<br />";
    
$tok strtok(" \n\t");
}
?>

Sunday, 1 May 2016

preg_replace_callback_array

$subject 'Aaaaaa Bbb';
preg_replace_callback_array(
    [
        
'~[a]+~i' => function ($match) {
            echo 
strlen($match[0]), ' matches for "a" found'PHP_EOL;
        },
        
'~[b]+~i' => function ($match) {
            echo 
strlen($match[0]), ' matches for "b" found'PHP_EOL;
        }
    ],
    
$subject);



6 matches for "a" found
3 matches for "b" found

preg_grep

// return all array elements
// containing floating point numbers
$array = array(120, 256.2, 985, 254, 654, 85.24, 65.9, 87);
$fl_array = preg_grep("/^(\d+)?\.\d+$/", $array);

print_r($fl_array);

Array
(
    [1] => 256.2
    [5] => 85.24
    [6] => 65.9
)