Page 1 of 2

Matching quote?

Posted: Sun Sep 25, 2005 10:24 am
by Ree

Code: Select all

$pattern = "#^[']+$#";
The above doesn't match single quote(s). How come? Is there anything special with quotes?

Posted: Sun Sep 25, 2005 10:27 am
by feyd
your pattern would require the entire line to have just single quote marks..

Posted: Sun Sep 25, 2005 10:33 am
by Ree
That's what I want! :) One or more quotes, that is.

Posted: Sun Sep 25, 2005 10:35 am
by s.dot
your line would have to be:

'''''''''''''''''''''''''
or
''''''
or '

or similar to match

anything else on that line like 'word' wouldn't match

Posted: Sun Sep 25, 2005 10:36 am
by feyd
Maybe you don't understand..it'll find

Code: Select all

''''''''''''''
it will not find

Code: Select all

'''a''''''''

Posted: Sun Sep 25, 2005 10:37 am
by Ree
Come on... The pattern I indicated is exactly what I want to match: one or more single quotes (ONLY quotes), nothing more, nothing less. But it won't match. That's why I'm asking what could the prob be.

Posted: Sun Sep 25, 2005 10:37 am
by feyd
how are you using it?

Posted: Sun Sep 25, 2005 10:40 am
by Ree
Simple textfield, trying to match $_POST['that_field'].

Posted: Sun Sep 25, 2005 10:41 am
by feyd
actual code would be nice to see.

Posted: Sun Sep 25, 2005 10:47 am
by Ree
Well, here you go:

The form:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>          
          <form method="post" action="http://192.168.0.153/test/test.php">
            <table class="form_table med_bg">
              <tr>
                <td><label>Value:</label></td>

                <td><input type="text" name="value" /></td>
              </tr>              
              <tr>
                <td><span>&nbsp;</span></td>
                <td><input type="submit" value="Submit" /></td>
              </tr>                  
            </table>
          </form>
</body>
</html>
test.php

Code: Select all

include('class.Validator.php');

$validator = &new Validator();

if ($validator->isName($_POST['value']))
{
  echo 'Valid.';
} else
{
  echo '<b>Invalid!</b>';
}
class.Validator.php:

Code: Select all

class Validator
{
  function Validator()
  {
  }

  function isName($value)
  {
    $pattern = "#^[']+$#";
    $matches = preg_match($pattern, $value);
    if ($matches > 0)
    {
      return true;
    }
    return false;
  }
}

Posted: Sun Sep 25, 2005 10:54 am
by Ree
I have just had a look inside php.ini and magic_quotes_gpc=On was the problem. Turning it off has solved the problem. :D

Posted: Sun Sep 25, 2005 10:55 am
by feyd
I'm going to guess you have magic quotes on. var_export($_POST['value']) somewhere...

Posted: Sun Sep 25, 2005 11:08 am
by Ree
Yeah, that's right. You missed my post above.

Posted: Sun Sep 25, 2005 11:10 am
by pilau
Magic quotes are the sux0rz. I haven't seen or heard even one good use for that option.
They'll probably remove it on the next version, if all it does is creating problems..

Posted: Fri Oct 21, 2005 10:45 am
by kendall
Woluldnt it be
"#'{1,}+#"