Niels
Niels

Reputation: 1006

Changing one specific lowercase letter to uppercase letter PHP

I am kinda new with PHP and I would love some help with converting a lowercase letter to an uppercase letter in an php echo (for example i to I)

So I currently use this line to output the url of the website:

<?php echo  "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; ?>

How do I get PHP to change only 1 letter to an capital letter in that line?

For example: http://idea.org/ to http://Idea.org/

Upvotes: 0

Views: 450

Answers (1)

scottw33
scottw33

Reputation: 96

Depending on what the purpose of this is, it might just be easier to use str_replace to change the name.

<?php echo  "http://" . str_replace('idea', 'Idea', $_SERVER['SERVER_NAME']) . $_SERVER['REQUEST_URI']; ?>

or you can ucfirst which will capitalize the first letter only. We should also use strtolower.

<?php echo  "http://" . ucfirst(strtolower($_SERVER['SERVER_NAME'])) . $_SERVER['REQUEST_URI']; ?>

Upvotes: 1

Related Questions