bschultz Posted May 26, 2009 Share Posted May 26, 2009 My company has four domain names. Each of the four websites uses the some of the same info gathered from a database...and I would like to replace the "we" with the company name. Here's the example of what might be in the database: We are going to have a float in the Memorial Day parade With this: The XYZ Company will have a float in the Memorial Day parade Obviously, I can't put php code into the database to determine which domain they are viewing the article from...so how can I enter the info into the database (and more importantly, retrieve it), so that the company name would replace "We"? Mind you, not all entries into the database will have a company name...so I can't just replace every "WE" with the "company name" Thanks. Brian Link to comment https://forums.phpfreaks.com/topic/159722-solved-retreive-domain-name/ Share on other sites More sharing options...
ToonMariner Posted May 26, 2009 Share Posted May 26, 2009 personally I would define the company name in each project.. define('COMP_NAME', 'XYZ Company'); so you will have one in each site. Afte that its a case of deciding which ones you wish to replace using something like: <?php ... $str = preg_replace('/we/i',COMP_NAME,$str); ... ?> Your problem is decerning which occurences are to be replaced... Link to comment https://forums.phpfreaks.com/topic/159722-solved-retreive-domain-name/#findComment-842466 Share on other sites More sharing options...
bschultz Posted May 26, 2009 Author Share Posted May 26, 2009 right...but I don't want to replace all "We"'s with Company Name. I'd like to have this in the database: <?php if (strpos(getenv('SERVER_name'), 'domanin1.com')!==false) { echo "Company 1"; } elseif (strpos(getenv('SERVER_name'), 'domanin2.com)!==false) { echo "Company 2"; } elseif (strpos(getenv('SERVER_name'), 'domain3.com')!==false) { echo "Company 3"; }; ?> will have a float in the Memorial Day Parade. but I can't insert php code into the database...but I can't think of any other way to only replace the company name when I want to...and not every time. Link to comment https://forums.phpfreaks.com/topic/159722-solved-retreive-domain-name/#findComment-842476 Share on other sites More sharing options...
bschultz Posted May 26, 2009 Author Share Posted May 26, 2009 Alright...I'm dumb. I was so set on replacing WE (since that's how I currently enter the info into the db) that it never dawned on my to enter COMPANYNAMEHERE (or some other completely random thing) into the db where the company name was supposed to go. Upon looking at preg_replace and how it needs to be written, how can I turn this: echo "<span class='itemdetails2'><br /><br />".stripslashes($row[story])."</span><br /><br /></td></tr>"; into the string to be replaced? Link to comment https://forums.phpfreaks.com/topic/159722-solved-retreive-domain-name/#findComment-842539 Share on other sites More sharing options...
ToonMariner Posted May 26, 2009 Share Posted May 26, 2009 if you are going to insert a specific term that is going to be replaced the we can just use the str_replace function - more effiecient as it doesn't have to do all the funky regex work. It will still need you to define the company name for each site and that would best be done as I suggested earlier - by defining a constant for each site (in this example I'll stick to the COMP_NAME). <?php echo "<span class='itemdetails2'><br /><br />".str_replace('COMPANYNAMEHERE',COMP_NAME,stripslashes($row[story]))."</span><br /><br /></td></tr>"; ?> That should accomplish all you need... Link to comment https://forums.phpfreaks.com/topic/159722-solved-retreive-domain-name/#findComment-842713 Share on other sites More sharing options...
bschultz Posted May 27, 2009 Author Share Posted May 27, 2009 That did it...thanks! It amazes me what php can do! Link to comment https://forums.phpfreaks.com/topic/159722-solved-retreive-domain-name/#findComment-842804 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.