[UPHPU] Help me speed this up. Possibly a regex question?

Lonnie Olson lists at kittypee.com
Tue Feb 12 17:50:33 MST 2008


Ash wrote:
> Is there a faster way to do this? Explanation below if this doesn't make 
> sense.
> 
>  $infile = "J-$Month-rs.pdf";
> 
> if (!file_exists($infile)){
>  $infile = "J-$Month-rp.pdf";
>         }
> if (!file_exists($infile)){
>  $infile = "J-$Month-ms.pdf";
>         }
> if (!file_exists($infile)){
>  $infile = "J-$Month-mp.pdf";
>         }
> if (!file_exists($infile)){
>  $infile = "J-$Month-rx.pdf";
>         }
> if (!file_exists($infile)){
>  $infile = "J-$Month-mx.pdf";
>         }
> if (!file_exists($infile)){
>  $infile = "J-$Month-xs.pdf";
>         }
> if (!file_exists($infile)){
>  $infile = "J-$Month-xp.pdf";
>         }
> if (!file_exists($infile)){
>  $infile = "J-$Month-xx.pdf";
>         }

You could at least use a simple array and a for loop.  And putting that 
in a function makes it even easier to read.

function find_files($Month) {
	$files = array( "J-$Month-rs.pdf", "J-$Month-rp.pdf", ....);
	foreach ($files as $file) {
		if (file_exists($file)) return $file;
	}
}
$infile = find_files($Month);

> 
> We have messages saved as images we put on a person's postcard according 
> to whether they are real estate or mortgage, or whether there is a 
> single photo or plural photos. See where it says J-$Month-rp? The rp 
> mean real estate plural. ms=Mortgage Singular, rx=real estate plural or 
> singular, mx=mortgage plural or singular, xx = either real estate or 
> mortgage, and either plural or singular. This all has to do with 
> grammar, ie, you would say "We'd love to help sell your home" if it is a 
> real estate team, whereas you'd put "I'd love to do your mortgage" if it 
> is a one-person mortgage card.
> 
> But if the message is something like "That was funny, huh?" It would get 
> an xx delineation, because the industry (mortgage or real estate) and 
> whether they are a singular person or a team doesn't matter in the message.
> 
> So I need it to go in this order-- first check if there is an r or m in 
> the first place and if there's also a p or s in the second place, if so 
> use the mp or rs message. If none of those are right, then we check to 
> see if there's a r or m in the first place and an x in the second place 
> or x in the first place and P or S in the second place, then use that 
> correct message. If none of those are there, use xx.
> 
> Is there a better way to do this with some regex magic or something?
> 
> Ash
> 
> _______________________________________________
> 
> 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