/    Sign up×
Community /Pin to ProfileBookmark

Variable Manipulation

In a PHP document I’m developing, I have the variable w that is taken from the URL, such as “/var.php?w=madd%20meeting”.

When w is called in my script, such as print $w, I’ll get “madd meeting”.

What I want to do is derive from w another variable (say “c”) that capitalize the first letters of the words in w, so I’ll get “Madd Meeting”.

I also want to be able to derive another variable from w (say “a”) that capitalizes all letters, so I’ll get “MADD MEETING”

I saw something online similar to what I want, but it requires setting up additional documents outside of my original document (var.php), and I really don’t want to do that. Also it didn’t address all letters capitalized.

Am I wanting too much from PHP?

Thanks for any help.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@pj59Jan 04.2005 — Hello![code=php]<?php
$w=$_GET['w'];
$c=split(' ',$w);
$a=array();
for ($i=0;$i<count($c);$i++){
$a[$i]=strtoupper($c[$i]);
$c[$i]=strtoupper(substr($c[$i],0,1)).substr($c[$i],1,strlen($c[$i]));
}
$c=join(' ',$c);
$a=join(' ',$a);
echo $w.'<br>'.$c.'<br>'.$a.'<br>';
?>[/code]
Regards PJ
Copy linkTweet thisAlerts:
@cyber1Jan 04.2005 — [code=php]print strtolower("$w")."n";
print ucwords("$w")."n";
print strtoupper("$w")."n";
[/code]


-Bill
Copy linkTweet thisAlerts:
@pj59Jan 04.2005 — Hi cyber1!

Didn't even know ucwords() and of course it is nonsense that I created an array for the all upper case stuff. :p

Thanks for teaching me that.

PJ
×

Success!

Help @shopkanji spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...