php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56653 Regular expression matches always return NULL
Submitted: 2005-11-15 19:26 UTC Modified: 2006-11-10 11:38 UTC
From: ramsey@php.net Assigned: pajoye (profile)
Status: Closed Package: filter (PECL)
PHP Version: 5.2.0 OS: Mac OS X 10.4.8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
6 + 8 = ?
Subscribe to this entry?

 
 [2005-11-15 19:26 UTC] ramsey@php.net
Description:
------------
Everytime I try to use the FL_REGEXP filter, it returns NULL. This is when compiled against the system's pcre.h.

Reproduce code:
---------------
<?php
var_dump(filter_data('foo', FL_REGEXP, array('regexp' => '/^\w+$/')));
?>

Expected result:
----------------
string(3) "foo"

Actual result:
--------------
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-15 19:48 UTC] ramsey@php.net
Thank you for taking the time to write to us, but this is not
a bug.

Removed the forward slash delimiters and it works. Manual should note that delimiters are not required (in fact, it will not work if the delimiters are provided).
 [2006-05-08 13:02 UTC] pierre dot php at gmail dot com
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.

You can use the same expression format as ext/pcre. It uses now the extension API.
 [2006-11-10 11:08 UTC] ramsey@php.net
I'm reopening this bug because, now, FILTER_VALIDATE_REGEXP always appear to return FALSE (even if removing the forward slash delimiters).

EXAMPLE CODE:

<?php

// $_GET['name'] = 'John Doe'
$name = 'John Doe';

$expression = '/^[[:alpha:]\ \-\']+$/';
$options = array('regexp' => $expression);

var_dump(filter_input(INPUT_GET, 'name', FILTER_VALIDATE_REGEXP, $options));

var_dump(preg_match($expression, $_GET['name']));

var_dump(filter_var($name, FILTER_VALIDATE_REGEXP, $options));

var_dump(preg_match($expression, $name));

?>

EXPECTED RESULT:

string(8) "John Doe"
int(1)
string(8) "John Doe"
int(1)

ACTUAL RESULT:

bool(false)
int(1)
bool(false)
int(1)
 [2006-11-10 11:38 UTC] ramsey@php.net
I'm closing this bug because my last comment was bogus. I should've been passing the options arguments like this:

array('options' => array('regexp' => $expression))

So, the comment wasn't even related to the earlier problems described here. The API simply changed, and I didn't notice it.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Oct 22 00:01:28 2019 UTC