自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

PHP ereg_replace()函數(shù)的工作原理解析

開發(fā) 后端
PHP ereg_replace()函數(shù)的函數(shù)原型為string ereg_replace (string $pattern, string $replacement, string $string)。我們將在文章中具體介紹它的相關(guān)用法。

我們在學(xué)習(xí)PHP語言的時候,經(jīng)常會和各種各樣的函數(shù)打交道,如何正確的理解這些函數(shù),對于我們的整個編碼程序有很大的幫助。今天我們就要為大家具體介紹有關(guān)PHP ereg_replace()函數(shù)的用法。

#t#PHP ereg_replace()函數(shù)原型:string ereg_replace (string $pattern, string $replacement, string $string)

string eregi_replace (string $pattern, string $replacement, string $string)

PHP ereg_replace()函數(shù)c,并將所匹配結(jié)果替換為$replacement。當(dāng)$pattern中包含模式單元(或子模式)時,$replacement中形如“\1”或“$1”的位置將依次被這些子模式所匹配的內(nèi)容替換。而“\0”或“$0”是指整個的匹配字符串的內(nèi)容。需要注意的是,在雙引號中反斜線作為轉(zhuǎn)義符使用,所以必須使用“\\0”,“\\1”的形式。

eregi_replace()和PHP ereg_replace()函數(shù)的功能一致,只是前者忽略大小寫。代碼6.6是本函數(shù)的應(yīng)用實(shí)例,這段代碼演示了如何對程序源代碼做簡單的清理工作。

PHP ereg_replace()函數(shù)代碼6.6 源代碼的清理

  1. < ?php   
  2. $lines = file('source.php'); //將文件讀入數(shù)組中  
  3. for($i=0; $i<count($lines); $i++)  
  4. {  
  5. //將行末以“\\”或“#”開頭的注釋去掉  
  6. $lines[$i] = eregi_replace("(\/\/|#).*$", "", $lines[$i]);   
  7. //將行末的空白消除  
  8. $lines[$i] = eregi_replace("[ \n\r\t\v\f]*$", "\r\n", $lines[$i]);   
  9. }  
  10. //整理后輸出到頁面  
  11. echo htmlspecialchars(join("",$lines));  
  12. ?> 

以上就是PHP ereg_replace()函數(shù)的相關(guān)用法介紹。

責(zé)任編輯:曹凱 來源: e897.com
相關(guān)推薦

2009-11-26 15:23:24

PHP函數(shù)ereg()

2009-11-30 17:06:35

PHP ereg()函

2017-05-31 13:16:35

PHP運(yùn)行機(jī)制原理解析

2019-08-20 14:01:22

HTTPSSSL協(xié)議

2009-11-26 15:35:43

PHP函數(shù)eregi(

2009-11-26 13:50:11

PHP函數(shù)str_re

2023-02-28 09:07:18

ChatGPTAI

2019-12-06 10:59:20

JavaScript運(yùn)行引擎

2021-07-12 09:45:36

NameServer 核心Conusmer

2021-01-12 14:46:34

Kubernetes開發(fā)存儲

2021-07-05 07:51:43

JVM底層Python

2024-11-01 08:57:07

2009-09-16 13:14:10

Ereg正則表達(dá)式

2010-09-26 10:09:25

dhcp relay工

2010-06-28 10:12:01

PHP匿名函數(shù)

2023-08-11 07:44:40

TCP滑動窗口數(shù)據(jù)

2021-12-01 18:36:35

屬性

2020-05-21 13:25:43

Spring組件架構(gòu)

2009-11-30 16:08:32

PHP addslas

2021-05-19 15:40:54

HTTPS前端加密
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號