On Sat, May 17, 2008 at 2:17 AM, Chris W <[EMAIL PROTECTED]> wrote:
> I need to find the position of the first character in the string
> (searching from the end) that is not one of the characters in a set.  In
> this case the set is [0-9a-zA-z-_]

    To find the position of a specific character, RTFM on strpos().
For those not existing in your condition, I'd recommend
everythingbut(), but it's yet to be included in the core.  ;-P

> I guess to be even more specific, I want to split a string into to parts
> the first part can contain anything and the second part must be only in
> the set described above.

    You can split a string by doing something as simple as this:

<?php
$str = "abcdefghijklmnopqrstuvwxyz";
$d = $str[5]; // $d == position - 1, because count always begins with 0
?>

    So to walk backward through the string, while it's not very clean,
you could do:

<?php
$str = "ABCDEF01234567789";

for($i=strlen($str);$i>0;$i--) {
    if(preg_match('/[g-z]/i',$str[$i])) {
        // Handle your "this is a bad character" condition(s).
        // break; /* Or, optionally, continue. */
    }
}
?>

    Not pretty, but if my mind is still working at 2:30a (EDT), it
should help you out.

-- 
</Daniel P. Brown>
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to