Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 40
W CZYM MOGĘ POMÓC?


   
OPINIE UŻYTKOWNIKÓW
Nie jestem webmasterem, ale i na mnie zrobiła wrażenie szybkość reakcji Darka na mój problem. Jego kompetencja i przede wszystkim zupełnie niemodna w dzisiejszych skomercjalizowanych czasach - zwykła ludzka życzliwość dla innego człowieka. Tacy ludzie to dziś gatunek niemal wymarły...

Leszek
Wojskowy Instytut Medyczny

   
GALERIA FOTOGRAFII
   
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net

[Spis] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [X] [W] [Z]

preg_grep

(PHP 4, PHP 5)

preg_grep --  Return array entries that match the pattern

Description

array preg_grep ( string pattern, array input [, int flags] )

preg_grep() returns the array consisting of the elements of the input array that match the given pattern.

flags can be the following flag:

PREG_GREP_INVERT

If this flag is passed, preg_grep() returns the elements of the input array that do not match the given pattern. This flag is available since PHP 4.2.0.

Since PHP 4.0.4, the results returned by preg_grep() are indexed using the keys from the input array. If this behavior is undesirable, use array_values() on the array returned by preg_grep() to reindex the values.

Przykład 1. preg_grep() example

<?php
// return all array elements
// containing floating point numbers
$fl_array = preg_grep("/^(\d+)?\.\d+$/", $array);
?>




User Contributed Notes

ak85 at yandex dot ru
03-Aug-2005 07:28

If U wanna find substring without word "BADWORD" U can use this expression:
/((?:(?!BADWORD).)*)/s
For example:
preg_match_all('/<b>((?:(?!</b>).)*)</b>/is',$string,$matches);
// U can find at the $matches substrings of $string between '<b>' and '</b>' without the same tag '</b>'

// Was found at O'Reilly Rerl Cookbook Russian Edition 2001


erik dot dobecky at NOSPAM dot fi-us dot com
30-Apr-2005 06:15

A useful way that we have developed filters against SQL injection attempts is to preg_grep the $_REQUEST global with the following regular expression (regex):

   '/[\'")]* *[oO][rR] *.*(.)(.) *= *\\2(?:--)?\\1?/'

which is used simply as:
<?php
$SQLInjectionRegex
= '/[\'")]* *[oO][rR] *.*(.)(.) *= *\\2(?:--)?\\1?/';
$suspiciousQueryItems = preg_grep($SQLInjectionRegex, $_REQUEST);
?>

which matches any of the following (case insensitive, a=any char) strings (entirely):

' or 1=1--
" or 1=1--
or 1=1--
' or 'a'='a
" or "a"="a
') or ('a'='a


Matt AKA Junkie
06-Jun-2004 09:05

To grep using preg_* from a string instead of an array, use preg_match_all().


zac at slac dot stanford dot edu
27-Jul-2002 04:02

preg_grep takes a third argument (PREG_GREP_INVERT) which negates the pattern matching behaviour, just like the "-v" flag to the grep command.

EXAMPLE:
$food = array('apple', 'banana', 'squid', 'pear');
$fruits = preg_grep("/squid/", $food, PREG_GREP_INVERT);
echo "Food  "; print_r($food);
echo "Fruit "; print_r($fruits);

RESULTS IN:
Food  Array
(
   [0] => apple
   [1] => banana
   [2] => squid
   [3] => pear
)
Fruit Array
(
   [0] => apple
   [1] => banana
   [3] => pear
)


 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt