★ wanayoo — archive 1999 http://www.php.net/manual/de/function.preg-quote.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to PCRE
Quick Reference
English version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
PCRE
* preg_match
* preg_match_all
* preg_replace
* preg_split
* preg_quote
* preg_grep
* Pattern Modifiers
* Pattern Syntax
Manual: preg_quote
View the source code for this pageSearch the site



Previous page
 preg_split
 Updated
Sat, 12 Aug 2000
preg_grep 
Next page


preg_quote

(PHP3 >= 3.0.9, PHP4 )

preg_quote -- Quote regular expression characters

Description

string preg_quote (string str)

preg_quote() takes str and puts a backslash in front of every character that is part of the regular expression syntax. This is useful if you have a run-time string that you need to match in some text and the string may contain special regex characters.

The special regular expression characters are:
. \\ + * ? [ ^ ] $ ( ) { } = ! < > | :

Anmerkung: This function was added in PHP 3.0.9.


User Contributed Notes: preg_quote


monte@ispi.net
18-Nov-1999 05:31
A good example of this is if you want to use a variable as search content that may contain characters with special meaning to PCRE.

Here I am making every occurance of $word italicized in $textbody. The variable $word may contain special characters and they will not affect the regular expression:

$textbody = preg_replace("|\b".preg_quote($word)."\b|","<i>".$word."</i>",$textbody);



 About Notes


Previous page
 preg_split
 Updated
Sat, 12 Aug 2000
preg_grep 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.