Miomir Dancevic
Miomir Dancevic

Reputation: 6852

CodeIgniter URL_TITLE model?

Here is example of URl_title CI, i know this code is do this

$title = "Whats wrong with CSS";

$url_title = url_title($title, '_', TRUE);

// Produces: whats_wrong_with_css

But hot to revers, is there a function in Ci to reverse something like this and return the true value? like this ?

// Produces: Whats wrong with CSS

Upvotes: 0

Views: 776

Answers (2)

mr_mark88
mr_mark88

Reputation: 1059

I would "extend" CI's URL helper by creating a MY_url_helper.php file in application/helpers and create a function similar to what umefarooq has suggested.

/*
 * Un-create URL Title
 * Takes a url "titled" string as de-constructs it to a human readable string.
 */
if (!function_exists('de_url_title')) {

    function de_url_title($string, $separator = '_') {

        $output = ucfirst(str_replace($separator, ' ', $string));

        return trim($output);
    }

}

Providing you have loaded the url helper, you will then be able to call this function throughout your application.

echo de_url_title('whats_wrong_with_css'); // Produces: Whats wrong with css

The second ($separator) paramater of the function allows you to convert the string dependent on whether it's been "url_title'd" with dashes - or underscores _

Upvotes: 0

umefarooq
umefarooq

Reputation: 4574

hi you can do it just with simple way

$title = ucfirst(str_replace("_",' ',$url_tilte));
echo $title;

Upvotes: 1

Related Questions