PHP中去除换行解决办法小结(PHP_EOL)_PHP
$content=str_replace("\n","",$content);
echo $content;
第二种写法:
str_replace("\r\n","",$str);
第三种写法:
$content=preg_replace("/\s/","",$content);
echo $content;
附:
首先说说\n,\r,\t
\n 软回车:
在Windows 中表示换行且回到下一行的最开始位置
在Linux、unix 中只表示换行,但不会回到下一行的开始位置。
\r 软空格:
在Linux、unix 中表示返回到当行的最开始位置。
在Mac OS 中表示换行且返回到下一行的最开始位置,相当于Windows 里的 \n 的效果。
\t 跳格(移至下一列)
几点说明:
它们在双引号或定界符表示的字符串中有效,在单引号表示的字符串中无效。
\r\n 一般一起用,用来表示键盘上的回车键(Linux,Unix中),也可只用 \n(Windwos中),在Mac OS中用\r表示回车!
\t表示键盘上的“TAB”键。
文件中的换行符号:
windows : \n
linux,unix: \r\n
实例代码:
复制代码 代码如下:
//php 不同系统的换行
//不同系统之间换行的实现是不一样的
//linux 与unix中用 /n
//MAC 用 /r
//window 为了体现与linux不同 则是 /r/n
//所以在不同平台上 实现方法就不一样
//php 有三种方法来解决
//1、使用str_replace 来替换换行
$str = str_replace(array("/r/n", "/r", "/n"), "", $str);
//2、使用正则替换
$str = preg_replace('//s*/', '', $str);
//3、使用php定义好的变量 (建议使用)
$str = str_replace(PHP_EOL, '', $str);
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.
