IMHO, you do are in position to tell the designers how the fields
should be named, after all they won't give any use to them, it's you (or
the developer in turn) who will deal with them. Besides, using
underscores (or any other space-replacement) anyone knows beforehand
what the text displayed will be, and any special combination of
lower/upper-case letters it's preserved.
Anyway, right now it seems this is something we can't depend on, so
let's refine the expression a little. Oh, and I was refering to the
same "problem" with fields such as "MyURL".
I've changed a little the pattern, now it would say "ignore the initial
lower-case letters and spaces (if any of those) and add a space before
any upper-case wich is not preceeded by an upper-case, and also those
upper-case followed by a lower-case", so it now would look like
$rex_initial = '/^[a-z]*\s*/X';
$rex_upper = '/(?<![A-Z])(?=[A-Z])|(?=[A-Z][^A-Z])/X';
$text = preg_replace($rex_initial, '',
preg_replace($rex_upper, ' ', $name) );
I think that solves the problem with the previous one. But I'd also
like to point out that most of us (you included, if I understood right)
seem to agree that this shouldn't be the first option, but something
simplier --this is more like a patch than a feature ;)
Good luck with the designers :)
Jay Blanchard wrote:
[···]
I was just headed in the wrong direction with preg_split(), and I had it
stuck in my head.
If I had delimiters, such as underscores, this question would have never
come up. I am not in a position to tell the designers that we need them
to change their naming conventions in forms at this unfortunately, so I
need to work with what we have as efficiently as possible.
Thank you for an elegant solution, but I am curious....why would it not
work with all field names if they were named using the conventions
(studly caps)? I can see a problem perhaps with a field named fooMyURL,
it would come out as My U R L. Do you feel as if there are any other
gotcha's?
--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
http://www.innox.com.mx
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php