You are here: Windows/ Unix regular expression question « PHP Programming Language « IT news, forums, messages
Windows/ Unix regular expression question

Posted by e_matthes on 05/29/07 15:44

Hello,

I have a function which uses a regular expression to validate text
input. Here's a short code sample testing the regex:

<?php

$dirty = "hello";
$clean = getCleanText($dirty, 0,50);
print "<br>dirty: $dirty<br>clean: $clean";

function getCleanText($textIn, $minLengthIn, $maxLengthIn) {

$acceptableTextRegExp = "/^[a-zA-Z0-9_\- ]\{$minLengthIn,
$maxLengthIn}/";
print "<br>$acceptableTextRegExp<br>";

if ( preg_match($acceptableTextRegExp, $textIn, $matchedArray) ) {
return $matchedArray[0];
} else {
return "";
}

} // END getCleanText($textIn, $minLengthIn, $maxLengthIn)

?>


The output on my local windows machine is:

/^[a-zA-Z0-9_\- ]{0,50}/
dirty: hello
clean: hello

The output from my web site on a shared unix server is:

/^[a-zA-Z0-9_\- ]\{0,50}/
dirty: hello
clean:

If I take out the \ before the open brace, both systems give me an
error about unmatched braces. Are escape characters handled
differently on windows and unix? Why does the unix version leave the
escape character in the reg ex string after parsing the string?

Thanks.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация