View Single Post
  #8 (permalink)  
Old Apr 19th, 2007, 17:16
grahame grahame is offline
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: There has to be an easier way

Masonbarge, I would tend to move all of your specific text OUT into a separate and easy to maintain data file rather than leave it in the program - the data might look like:

Code: Select all
allpurp,all-purpose,
 and , & ,
 appl , apple ,
asprt,aspatame,
bf,beef,
bn,bean,
etc
and then the conversion could be shortened to:

Code: Select all
<?php
$food_name = " appl and bf pie";
print ("$food_name<br>\n");
foreach (file("changeit.txt") as $line) {
        list($change,$into) = explode(",",$line);
        $food_name = preg_replace("/$change/i",$into,$food_name);
        }
print ("$food_name<br>\n");
?>
Of course, if you get paid by the line of code written or want to retain control in the programmer's hands, this approach probably isn't for you
Reply With Quote