[UPHPU] Help me simplify this bit of code please?

William Attwood wattwood at gmail.com
Mon Aug 25 15:08:14 MDT 2008


instead of substr(2,2) you could say substr(2, len($string));


or, you could go:
$var = 'FF02';

$var1 = preg_replace('/[0-9]/', '', $var);
$var2 = preg_replace('/[a-z]/i', '', $var);
$var2 = '/'.$var2;

thereby giving you all digits, and all numerics.  Not the most ideal, but if
you can verify that the input is only CharCharNumNum or CharCharNum then
you're set.

What'll break it is CharNumCharCharNum, or any mix therein.

-Will


On Mon, Aug 25, 2008 at 2:58 PM, Ash <ashovi at qwest.net> wrote:

> Sorry, I forgot to add another line of the code that makes it so that
> substr won't work, at least reading from right to left. From left to right,
> it will, because there is always 2 chars for the description, but perhaps
> only 1 for the year.
>
>
> case 'FF2':
>                            $series_year = "2";
>  $series_description = "/FF";
>                    break;
>
> I'm sure there's a way to make substr read from left to right, but I don't
> know how to do the counting for it.
>
> Ash
>
>  $servies_year = substr($series,0,2);
>> $servies_year = substr($series,2,2);
>>
>> something along those lines may work.
>>
>> On Mon, Aug 25, 2008 at 1:31 PM, Ash <ashovi at qwest.net <mailto:
>> ashovi at qwest.net>> wrote:
>>
>>    switch ($series)
>>                   {
>>                   case 'FF12':
>>                           $series_year = "12";
>>                           $series_description = "/FF";
>>                   break;
>>
>>                   case 'FF13':
>>                           $series_year = "13";
>>                           $series_description = "/FF";
>>                   break;
>>
>>
>
>
> _______________________________________________
>
> UPHPU mailing list
> UPHPU at uphpu.org
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net
>


More information about the UPHPU mailing list