Misc Function in PHP: Part 3

Introduction

In this article I describe the PHP Miscellaneous functions highlight_string, ignor_user_abort, pack, strip_whitespace and show_source. To learn some other FileSystem functions, go to:

  1. Misc Function in PHP: Part 1
  2. Misc Function in PHP: Part 2

PHP highlight_string() Function

The PHP Miscellaneous highlight_string function is used to highlight the syntax of a string and it returns the highlighted code as a string instead of printing it out or say it will return TRUE on success or FALSE on failure.

Syntax

highlight_string(string,return)

Parameter in highlight_string function

The parameter of the function is:

Parameter Description
string It specifies the string to highlight.
return It you set this parameter to TRUE, then this function will return the highlighted code as a string.

Example

An example of the
function is:

<
html>
<
body>
<?
php
highlight_string
("Hello! <?php phpinfo();?>");
?>
</
body>
</
html>

Output


highlight-string-function-in-php.gif

PHP ignore_user_abort() Function

The PHP Miscellaneous ignor_user_abort function set whether a disconnected client should abort script execution and it returns the previous setting, as an integer.

Syntax

ignore_user_abort(setting)

Parameter in ignore_user_abort function

The parameter of the function is:

Parameter Description
setting If it set to TRUE then user aborts in a script.

Example

An example of the
function is:

<?php

print_r(ignore_user_abort());

?>

Output


ignore-user-abort-function-in-php.gif

PHP pack() Function

The PHP Miscellaneous pack function is used to pack data into a binary string or set; it returns a binary string containing the data.

Syntax

pack(format,args+)

Parameter in pack function

The parameters of the function are:

Parameter Description
format It specifies the format to use when packing data and its possible values are:
  • a - It specifies NUL-padded string.
  • A - It specifies SPACE-padded string.
  • c - It specifies signed char.
  • C - It specifies unsigned char.
  • d - It specifies double (machine dependent size and representation).
  • f - It specifies float (machine dependent size and representation).
  • h - It specifies hex string, low nibble first.
  • H - It specifies hex string, high nibble first.
  • i - signed integer (machine dependent size and byte order).
  • I - It specifies unsigned integer (machine dependent size and byte order).
  • l - It specifies signed long (always 32 bit, machine byte order).
  • L - It specifies unsigned long (always 32 bit, machine byte order).
  • n - It specifies unsigned short (always 16 bit, big endian byte order).
  • N - It specifies unsigned long (always 32 bit, big endian byte order).
  • s - It specifies signed short (always 16 bit, machine byte order).
  • S - It specifies unsigned short (always 16 bit, machine byte order).
  • v - It specifies unsigned short (always 16 bit, little endian byte order).
  • V - It specifies unsigned long (always 32 bit, little endian byte order).
  • x - It specifies NUL byte.
  • X - It specifies Back up one byte.
  • @ - It specifies NUL-fill to absolute position.
args+ It specifies one or more arguments to be packed.

Example

An example of the
function is:

<?
php
echo
pack('C4', 128, 9, 176, 32)."</br>";
echo
pack('C3',80,72,80);
?>


Output


pack-function-in-php.gif

PHP strip_whitespace() Function

The PHP Miscellaneous strip_whitespace function is used to return the source code of the specified file with the PHP comment and whitespace removed or say it returns the stripped source code on success or an empty string on failure.

Syntax

strip_whitespace(filename)

Parameter in strip_whitespace function

The parameter of the function is:

Parameter Description
filename It specifies the file to strip.

Example

An example of the
function is:

<?
php
//
PHP comment here
/*

 * Another PHP comment

 */

 

echo        php_strip_whitespace    ("test.txt");

?>

Output

strip-white-space-function-in-php.gif

View Source Code

source-code.gif

PHP show_source() Function

The PHP Miscellaneous show_source function is the alias of the highlight_fie function, in other words it outputs a file with the PHP syntax highlighted and it returns the highlighted code as a string instated of printing it out.

Syntax

show_source(filename,return)

Parameter in show_source function

The parameter of the function is:

Parameter Description
filename It specifies the file to display.
return If this parameter is set to true then this function will return the highlighted code as a string.

Example

An example of the
function is:

<
html>
<
body>
<?
php
show_source
("showsource.php");
?>
</
body>
</
html>

Output

show-source-function-in-php.gif


Similar Articles