IntricatePixels
IntricatePixels

Reputation: 1229

php - Find and replace two types of matches in a string using preg_replace

I'm trying to replace dashes and the '.php' extension on a string, for example:

Original String:

my-awesome-link.php

Resulting String:

My Awesome Link

Any help greatly appreciated!

Upvotes: 0

Views: 110

Answers (2)

The full solution would be this:

$pageName = ucwords(str_replace(['-','.php'],[' ',''], $getPageName[1]));

Upvotes: 0

LSerni
LSerni

Reputation: 57408

You can use str_replace to get rid of both '-' and '.php', then UCWords to go from 'my awesome link' to 'My Awesome Link'.

Upvotes: 2

Related Questions