search
Homephp教程php手册PHP清除字符串中所有无用标签的方法,php字符串

PHP清除字符串中所有无用标签的方法,php字符串

本文实例讲述了PHP清除字符串中所有无用标签的方法。分享给大家供大家参考。具体实现方法如下:

很多时候需要输出一些 “纯” 字符串,也就是去除任何杂质,例如 Html 标签、空格之类的文本,输出的摘要就是如此,下面的这个函数可以帮你实现着一点.

PHP实例代码如下:

复制代码 代码如下:

function Bing_string_cleanr( $string ){
 $string = trim( $string ); 
 $string = strip_tags( $string );
 $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8' );
 $string = str_replace( "n", "", $string );
 $string = trim( $string );
 return $string;
}


使用方法如下:

复制代码 代码如下:

echo Bing_string_cleanr( '内 容
asdfeiuonsdfje' );

php删除空白,代码如下:

复制代码 代码如下:

$str = " This line containstliberal rn use of whitespace.nn";
 
// First remove the leading/trailing whitespace
//去掉开始和结束的空白
$str = trim($str);
 
// Now remove any doubled-up whitespace
//去掉跟随别的挤在一块的空白
$str = preg_replace('/s(?=s)/', '', $str);
 
// Finally, replace any non-space whitespace, with a space
//最后,去掉非space 的空白,用一个空格代替
$str = preg_replace('/[nrt]/', ' ', $str);
// Echo out: 'This line contains liberal use of whitespace.'
echo "

{$str}
";
?>

希望本文所述对大家的PHP程序设计有所帮助。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)