jasonaud Posted February 8, 2008 Share Posted February 8, 2008 First off i know im a noob at this stuff but have been searching for 2 days and this is a last resort before hiring someone. i need help with a str_replace expression and a rewrite. str_replace expression. what i need to do is replace 26 different items and have it write them differently. this is going to be called in 2 spots on my site. 1 is in the title tag and the other is in the page its self. here is the 26 str_replace statements. i already know i did it totally wrong. //$typename = str_replace("dailyteenhoroscopes", "Daily Teen", "$type"); //$typename = str_replace("dailyoverview", "Daily Overview", "$type"); //$typename = str_replace("dailyextended", "Daily Extended", "$type"); //$typename = str_replace("dailysingleslove", "Daily Singles Love", "$type"); //$typename = str_replace("dailycoupleslove", "Daily Couples Love", "$type"); //$typename = str_replace("dailyflirt", "Daily Flirt", "$type"); //$typename = str_replace("dailywork", "Daily Work", "$type"); //$typename = str_replace("dailyquickie", "Daily Quickie", "$type"); //$typename = str_replace("dailygreenscope", "Daily GreenScope", "$type"); //$typename = str_replace("dailybeautyscope", "Daily BeautyScope", "$type"); //$typename = str_replace("dailyastroslam", "Daily AstroSlam", "$type"); //$typename = str_replace("dailybabyscope", "Daily BabyScope", "$type"); //$typename = str_replace("dailycatscope", "Daily CatScope", "$type"); //$typename = str_replace("dailydogscope", "Daily DogScope", "$type"); //$typename = str_replace("dailyhomeandgarden", "Daily Home and Garden", "$type"); //$typename = str_replace("dailygayscope", "Daily GayScope", "$type"); //$typename = str_replace("dailylesbianscope", "Daily LesbianScope", "$type"); //$typename = str_replace("dailychinese", "Daily Chinese", "$type"); //$typename = str_replace("weeklybusiness", "Weekly Business", "$type"); //$typename = str_replace("weeklyoverview", "Weekly Overview", "$type"); //$typename = str_replace("weeklytravel", "Weekly Travel", "$type"); //$typename = str_replace("weeklyflirt", "Weekly Flirt", "$type"); //$typename = str_replace("weeklyromantic", "Weekly Romantic", "$type"); //$typename = str_replace("monthlyoverview", "Monthly Overview", "$type"); //$typename = str_replace("monthlyfitness", "Monthly Fitness", "$type"); //$typename = str_replace("monthlycareer", "Monthly Career", "$type"); //$typename = str_replace("monthlyromantic", "Monthly Romantic", "$type"); 2nd problem htaccess rewrite i need to make this url into a seo url these are the urls i have now on the site. there are 312 different ones. they all follow this format. index.php?sign=Aries&type=dailyoverview&p=1 index.php?sign=Libra&type=dailyteenhoroscopes&p=1 into domain.com/Aries/dailyoverview/1 or domain.com/sign/Libra/type/dailyteenhoroscope/p/1 what ever one is better. If someone can help it would be great. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/90021-solved-need-help-with-2-items/ Share on other sites More sharing options...
Psycho Posted February 8, 2008 Share Posted February 8, 2008 You don't say WHAT is not working with yur str_replace functions, but I will take a guess. 1) They are all commented out. 2) The first line will replace the first value in the $type variable and assign that result to $typename. however the next line will replace the 2nd value IN THE ORIGINAL $type variable (in other words you just lost the replacement on the first line). This continues all the way to the end, so only the last replacement is done. 3) This won't keep it from working, but there's no need to enclose $type in quotes. however, there is a much easier way to do this by using arrays: <?php $codes = array('dailyteenhoroscopes', 'dailyoverview', 'dailyextended', 'dailysingleslove'); $texts = array ('Daily Teen', 'Daily Overview', 'Daily Extended', 'Daily Singles Love'); //I only included four sets, just add all of the strings to these arrays $typename = str_replace($codes, $texts, $type); ?> Quote Link to comment https://forums.phpfreaks.com/topic/90021-solved-need-help-with-2-items/#findComment-461567 Share on other sites More sharing options...
jasonaud Posted February 8, 2008 Author Share Posted February 8, 2008 thank you a ton on that array. ive been searching all over. i know it could be done with an array but didnt know how. that worked perfect. now just to find the hard rewrite code. Quote Link to comment https://forums.phpfreaks.com/topic/90021-solved-need-help-with-2-items/#findComment-461571 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.