Hmm. so you want a lookup table? How about an associative array?
<?
$search_array = array ("apple"=>"app", "banana"=>"ban",
"cantolope"=>"cant");
$targetKey="apple";
if (key_exists($targetKey, $search_array))
echo($targetKey." transposes to ".$search_array[$targetKey]);
?>
outputs:
apple transposes to app
If you wanted to save the array as a file, you could use the function
"serialize", and then write it out. To read it back in you'd need to
"unserialize"
see:
http://www.php.net/manual/en/function.fwrite.php
http://www.php.net/manual/en/function.fread.php
http://www.php.net/manual/en/function.serialize.php
http://www.php.net/manual/en/function.unserialize.php
cheers,
Ryan
> i have a PHP question for any PHP guros listening...
>
> i would like to create dictionary (a file) to compare variables against... to
> replace them when they match certain criteria. i have used "PHP_SELF" to pull each
> page of a website's location and then am using that information (after parsing) to
> dynamically fill content.
>
> example:
>
> if the URL is...
>
> http://example.com/products/
>
>
> ...then the code for the products navigational menu will automatically apear. this
> works because there is an...
>
> "<php include($DOCUMENT_ROOT."/includes/nav/$L2.inc"); ?>"
>
>
> ...in the page.
>
> after parsing the "PHP_SELF"... i have the data that i need for "level two" ("$L2"),
> in variable "$dChunks[2]," but the problem is that it is "products" (from the folder
> name in the URL). my navigational include file is named "pro.inc" instead of
> "products." sure, the first reaction would be to rename the includes, but... i have
> some long and some non-asthetically-pleasing folder names.
>
> so... i would like to create a variable dictionary that is just a file full of
> variable names. and then a litle script that says...
>
> "if $variable_A is in the dictionary, then replace it with it's short name"
>
> does that make sense?
>
> i'm not asking for someone to write this. what i'm asking is if anyone has any
> experience doing this and/or if they have any suggestions/recommendations on how to
> do it best. or, if they know of any examples around on the best way to implement
> something like this.
>
> i thought it would be good to ask, as i'm pretty sure that dictionary replacing like
> this is done often in programming.
>
> thanks for you help,
>
> wade preston
>
>
> ____________________________________________________________
> Free 20MB Web Site Hosting and Personalized E-mail Service!
> Get It Now At Doteasy.com http://www.doteasy.com/et/
>
> ____________________
> BYU Unix Users Group
> http://uug.byu.edu/
> ___________________________________________________________________
> List Info: http://phantom.byu.edu/cgi-bin/mailman/listinfo/uug-list
____________________
BYU Unix Users Group
http://uug.byu.edu/
___________________________________________________________________
List Info: http://phantom.byu.edu/cgi-bin/mailman/listinfo/uug-list