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
Post
by Ree » Sun Sep 25, 2005 10:24 am
The above doesn't match single quote(s). How come? Is there anything special with quotes?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Sep 25, 2005 10:27 am
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 » Sun Sep 25, 2005 10:33 am
That's what I want!
One or more quotes, that is.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Sun Sep 25, 2005 10:35 am
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Sep 25, 2005 10:36 am
Maybe you don't understand..it'll find
it will not find
Ree
Forum Regular
Posts: 592 Joined: Fri Jun 10, 2005 1:43 am
Location: LT
Post
by Ree » Sun Sep 25, 2005 10:37 am
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Sep 25, 2005 10:37 am
how are you using it?
Ree
Forum Regular
Posts: 592 Joined: Fri Jun 10, 2005 1:43 am
Location: LT
Post
by Ree » Sun Sep 25, 2005 10:40 am
Simple textfield, trying to match $_POST['that_field'].
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Sep 25, 2005 10:41 am
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 » Sun Sep 25, 2005 10:47 am
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> </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 » Sun Sep 25, 2005 10:54 am
I have just had a look inside php.ini and magic_quotes_gpc=On was the problem. Turning it off has solved the problem.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Sep 25, 2005 10:55 am
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 » Sun Sep 25, 2005 11:08 am
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 » Sun Sep 25, 2005 11:10 am
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..
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Fri Oct 21, 2005 10:45 am
Woluldnt it be
"#'{1,}+#"