I have a script that displays the home page URL for a series of websites both locally and online. For example, the value for $MySite_URL on my laptop might be MS, while the value online might be www.mysite.com.
When inserted in text, the values look like this:
(See <a href="<php echo $MS_URL; ?>">MySite.com</a>)
But now that I’m putting my text into database tables, those PHP scripts don’t work. So I replaced the echo value with this:
(See <a href=“$MS_URL”>MySite.com</a>)
Then I just use str_replace to replace $MS_URL with the php code, like this…
$Text = str_replace($URL_That, $URL_This, $Text);
And here’s what my array looks like:
$URL_That = array('$G_URL', '$PX_URL');
$URL_This = array(''.$G_URL.'', ''.$PX_URL.'');
So here’s my question: I have a lot of websites to put in this array and will have to add more as I create more websites. Since every value ends with _URL, is there a PHP or regex code I can use to shorten this to a single “floating value”? I’m thinking of something like this:
$URL_That = array('$*_URL');
$URL_This = array(''.$*_URL.'');
All the website ID’s consist of one, two or three characters followed by _URL: G_URL, GW_URL, BBW_URL, DB_URL. All the letters are capitalized. However, a few contain numerals, usually a 2: URL_BR2.
I thought I might be able to use some variation of this script, which includes a file if a URL = a single capital letter, but I haven’t figured out how to rewrite it:
if (preg_match("/^[A-Z]$/", $MyURL)) {
$GlossarySeries = 'Alphabet';
[include something]
}
else {
include_once($BaseINC."/404.php");
}
Thanks for any tips.