I’m using PHP to help me develop an ePub that includes a series of tables that include the names of the various U.S. states. Each state name is linked to its own page, and all the links in each table target the same anchor…
…/alaska#bird
…/colorado#bird
Rather than insert the name of a state, with the html link, over and over and over, I’d like to just type in ‘.$AZ.’, which would then echo the linked word Arizona (e.g. Arizona).
So far, it’s simple. I just include a file that features the values for each of the 50 states, $AL through $WY. The problem: How do I insert a unique anchor value for each table?
Here’s one possibility…
First, I create my 50 state values…
$AZ = '<a href="'.$StatesHomeLink.'az.'.$XHTML.'#XYZ" title="Arizona">Arizona</a>';
Next, I use str_replace to replace XYZ with an anchor value. I would paste the following line of code just before the Food table, for example:
$AZ = str_replace('XYZ', 'food', $AZ);
That, too, is simple…for a single value. However, I need to modify all 50 state values for each table, something like this…
$AZ = str_replace('XYZ', 'food', $AZ);
$CA = str_replace('XYZ', 'food', $CA);
Is there some way to expedite this, so i don’t have to paste 50 lines of code with a different anchor in front of each table?
It looks like this is something I could do with an associative array. I would create a master array, then include a line of code modifying the anchor link just before each table. Then I can type in ‘.$AZ.’ and it will automatically link to a page with a specific anchor (e.g. #food).
However, I don’t know exactly how to create such an array, or how to modify the anchor links.
Thanks for any tips.