Php variables

They have: 18 posts

Joined: Nov 2002

Hello. I have a question about Php.

<?php

$p
= \"starcraft\";
echo(\"
$p\");
?>

The code above will output "starcraft" on my page. My question is, is there a way to make the first letter caps? On the page it it would appear "Starcraft" instead of "starcraft", but the value would still be $p = "starcraft".

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

He has: 1,016 posts

Joined: May 2002

There are actually 2 options depending on your needs...

<?php
$p
= \"hello world\";
echo ucfirst(
$p); // This will print \"Hello world\" (UC first char only)
echo ucwords(
$p); // This will print \"Hello World\" (UC first char of all words)
?>

They have: 18 posts

Joined: Nov 2002

Thank you for your help.

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

Well, I guess you really DO learn something new every day
Thanks for the tip

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.