Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

"\" ");


?>


string chr(integer ascii_code)


Use chr to get the character for an ASCII code. This function is helpful for situations
where you need to use a nonprinting character that has no backslash code, or the
backslash code is ambiguous. Imagine a script that writes to a formatted text file.
Ordinarily you would use \n for an end-of-line marker. But the behavior may be
different when your script is moved from Windows to Linux, because Windows uses a
carriage return followed by a linefeed. If you wish to enforce that each line end with a
linefeed only, you can use chr(10) as in the example below.


Of course, you may always use a backslash code to specify an ASCII code, as listed in
Appendix A and discussed in Chapter 2. Another alternative to chr is sprintf.
The %c code stands for a single character, and you may specify an ASCII value for the
character. Additionally, some functions, such as ereg_replace, accept integers that
are interpreted as ASCII codes.


If you need the ASCII code for a character, use ord. Appendix B lists ASCII codes.


<?


//open a test file
$fp = fopen("data.txt", "w");


//write a couple of records that have
//linefeeds for end markers
fwrite($fp, "data record 1". chr(10));
fwrite($fp, "data record 2". chr(10));


File Uploads........................................................................................................


fclose ($fp);
?>


string chunk_split(string data, integer length, string marker)


The chunk_split function returns the data argument after inserting an end-of-line
marker at regular intervals. By default a carriage return and a linefeed are inserted every
76 characters. Optionally, you may specify a different length and a different marker
string.

Free download pdf