第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

刪除多個空格

刪除多個空格

藍山帝景 2019-10-06 13:20:50
我$row['message']從MySQL數(shù)據(jù)庫獲取數(shù)據(jù),我需要刪除所有空白\n \t,依此類推。$row['message'] = "This is   a Text \n and so on \t     Text text.";應格式化為:$row['message'] = 'This is a Text and so on Text text.';我試過了: $ro = preg_replace('/\s\s+/', ' ',$row['message']); echo $ro;但不會刪除\n或\t,而只能刪除單個空格。誰能告訴我該怎么做?
查看完整描述

4 回答

?
犯罪嫌疑人X

TA貢獻2080條經(jīng)驗 獲得超4個贊

你需要:


$ro = preg_replace('/\s+/', ' ',$row['message']);

您使用的\s\s+是指空格(空格,制表符或換行符)后跟一個或多個空格。這實際上意味著用單個空格替換兩個或多個空格。


您想要的是用單個空格替換一個或多個空格,因此您可以使用模式  \s\s*或\s+(推薦)


查看完整回答
反對 回復 2019-10-06
?
慕的地8271018

TA貢獻1796條經(jīng)驗 獲得超4個贊

<?php

$str = "This is  a string       with

spaces, tabs and newlines present";


$stripped = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $str);


echo $str;

echo "\n---\n";

echo "$stripped";

?>

這個輸出


This is  a string   with

spaces, tabs and newlines present

---

This is a string with spaces, tabs and newlines present


查看完整回答
反對 回復 2019-10-06
?
12345678_0001

TA貢獻1802條經(jīng)驗 獲得超5個贊

簡化為一個功能:


function removeWhiteSpace($text)

{

    $text = preg_replace('/[\t\n\r\0\x0B]/', '', $text);

    $text = preg_replace('/([\s])\1+/', ' ', $text);

    $text = trim($text);

    return $text;

}

根據(jù)Danuel O'Neal的回答。


查看完整回答
反對 回復 2019-10-06
  • 4 回答
  • 0 關注
  • 710 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號