---
title: "preg_quote — 转义正则表达式字符"
author: "strayly"
date: "2018-03-16T10:34:37Z"
tags: []
categories: ["编程语言"]
slug: "preg-quote"
draft: false
lastmod: "2018-03-16T10:34:37Z"
id: 2413281
url: "https://strayly.iteye.com/blog/2413281"
---

说明 

string preg_quote ( string $str  )

preg_quote()需要参数 str 并向其中 每个正则表达式语法中的字符前增加一个反斜线。 这通常用于你有一些运行时字符串 需要作为正则表达式进行匹配的时候。 

正则表达式特殊字符有： . \ + * ?  $ ( ) { } = ! < > | : - 

示例:$txt = preg_replace('/'.preg_quote($word1).'/i',$wod2,$txt,$count);