$php_mysql$ Posted July 12, 2011 Share Posted July 12, 2011 when i call my category they from a page i do this $catname = clean($_REQUEST['category']); now my categories names are fixed such as career_jobs, buy_sell so i wish to change my page title to say if category buy_sell comes in the $_REQUEST i want to replay it with Buy & Sell on the page title if Career_Jobs comes then i wish to change the title to Career & Jobs, how could i do this? Link to comment https://forums.phpfreaks.com/topic/241795-how-to-replace-a-matching-string/ Share on other sites More sharing options...
$php_mysql$ Posted July 12, 2011 Author Share Posted July 12, 2011 nevermind str_replace did the job :-) but how could i add a if statement or by using array mebbe and add multiple replacements? any help? i need to modify just 3 category names in the $title rest should remain as it is Link to comment https://forums.phpfreaks.com/topic/241795-how-to-replace-a-matching-string/#findComment-1241773 Share on other sites More sharing options...
AbraCadaver Posted July 12, 2011 Share Posted July 12, 2011 Two ways depending on the variety of your strings: $title = str_replace('_', ' & ', ucwords($catname)); Or something with a lookup array: $lookup = array('career_jobs' = > 'Career & Jobs', 'buy_sell' => 'Buy & Sell'); if(isset($lookup[strtolower($catname)])) { $title = $lookup[strtolower($catname)]; } else { $title = 'not found'; } Link to comment https://forums.phpfreaks.com/topic/241795-how-to-replace-a-matching-string/#findComment-1241776 Share on other sites More sharing options...
$php_mysql$ Posted July 12, 2011 Author Share Posted July 12, 2011 walla bro thanks soo much :-) this solved my issue :-) $title = str_replace('_', ' & ', ucwords($catname)); Link to comment https://forums.phpfreaks.com/topic/241795-how-to-replace-a-matching-string/#findComment-1241777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.