Jump to content

how to replace a matching string?


$php_mysql$

Recommended Posts

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

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';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.