0

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!

2
  • And what have you tried so far? Commented Sep 12, 2012 at 22:58
  • 1
    No need for preg_replace. Just make str_replace(['-', '.php'], [' ', ''], $text) Commented Sep 12, 2012 at 22:58

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I got this far: $pageName = str_replace( "-", ' ', ucwords($getPageName[1]) ); How to I str_replace the '.php' value also?
0

The full solution would be this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.