Reply to Re: Help me with a regular expression for PHP

Your name:

Reply:


Posted by Pedro Graca on 10/30/06 02:17

cendrizzi top-posted and totally messed it up:
> I hoped I could use RE to check from the start if it had that so it
> wouldn't require the extra string searches.


<?php
$data = array(
'<input type="text" name="no!" id="test0"> ',
'<input type="text" name="no{!}" id="test0"> ',
'<input type="text" name="test0" id="test0"> ',
'<input type="text" name="test 0" id="test0"> ',
'<input type="text" name="test{0}" id="test0"> ',
'<input type="text" name="test {0}" id="test0"> ',
'<input type="text" name="test{0}test" id="test0"> ',
'<input type="text" name="test {0} test" id="test0">',
);
$rx = '/<(input|select|textarea)[^>]*' .
# 'name\s*\=\s*\"[_a-zA-Z0-9\s]*\"' . // your original version
'name\s*\=\s*\"[_a-zA-Z0-9\s]*{[_a-zA-Z0-9\s]*}[_a-zA-Z0-9\s]*\"' .
# ---^--- ---^---
'[^>]*>/';
### I think there's a few \ too many in there,
### I didn't look at it very attentively

foreach ($data as $val) {
echo $val, ' :: ';
if (preg_match($rx, $val)) {
echo 'M';
} else {
echo 'No m';
}
echo "atch.\n";
}
?>

--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.

[Back to original 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

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