Matching quote?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Matching quote?

Post by Ree »

Code: Select all

$pattern = "#^[']+$#";
The above doesn't match single quote(s). How come? Is there anything special with quotes?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your pattern would require the entire line to have just single quote marks..
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

That's what I want! :) One or more quotes, that is.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Maybe you don't understand..it'll find

Code: Select all

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

Code: Select all

'''a''''''''
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post 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.
Last edited by Ree on Sun Sep 25, 2005 10:39 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

how are you using it?
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

Simple textfield, trying to match $_POST['that_field'].
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

actual code would be nice to see.
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post 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;
  }
}
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm going to guess you have magic quotes on. var_export($_POST['value']) somewhere...
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

Yeah, that's right. You missed my post above.
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post 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..
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Woluldnt it be
"#'{1,}+#"
Post Reply