01c04-1.php
来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 34 行
PHP
34 行
<?php// Declare our generic function that will fix all these problems.// $subject will be the string to fix, and $type will be the // format that you wish in the end, either 'unix', 'mac', or 'pc'function line_break_set($subject, $type) { // Determine our replacement switch ($type) { case 'mac': $ending = '\r'; break; case 'pc': $ending = '\r\n'; break; default: $ending = '\n'; } // Now perform the replacement return preg_replace('/\r\n|\n\r|\n|\r/', $ending, $subject);}$str = "Multiple\rtypes of\n\rline breaks\r\nhave been placedwithin this string\n\nSee?";// Convert this three times now$mac = line_break_set($str, 'mac');$unix = line_break_set($str, 'unix');$pc = line_break_set($str, 'pc');// Echo out the strings, using addcslashes to make the line breaks visible.echo '<pre>mac = ', addcslashes($mac, "\n\r"), "\npc = ", addcslashes($pc, "\n\r"), "\nunix = ", addcslashes($unix, "\n\r"), '</pre>';?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?