By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,829 Members | 2,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,829 IT Pros & Developers. It's quick & easy.

Perl to PHP conversion

P: 2
I needed help in converting following perl function into php:

sub texttool {
$tool =~ tr/A-Z/a-z/;
@tool = split(/ /, $tool);
foreach $word(@tool) {
$tit1 = $word;
$tit2 = $word;
$tit1=(($tit1=~/(.{0,1})/) ? $1 : '');
$tit2 = reverse $tit2;
chop($tit2);
$tit2 = reverse $tit2;
$tit1 =~ tr/a-z/A-Z/;
$word = "$tit1$tit2";
}
$tool = join(' ',@tool);
}
Feb 28 '07 #1
Share this Question
Share on Google+
1 Reply


P: 99
I needed help in converting following perl function into php:

sub texttool {
$tool =~ tr/A-Z/a-z/;
@tool = split(/ /, $tool);
foreach $word(@tool) {
$tit1 = $word;
$tit2 = $word;
$tit1=(($tit1=~/(.{0,1})/) ? $1 : '');
$tit2 = reverse $tit2;
chop($tit2);
$tit2 = reverse $tit2;
$tit1 =~ tr/a-z/A-Z/;
$word = "$tit1$tit2";
}
$tool = join(' ',@tool);
}
as far as i can tell in php it would be something like this
[PHP]
function texttool($tool){
$tool = strtolower($tool);
$toolarr = split(' ',$tool);
$toolarr2 = array()
foreach($toolarr as $word){
$tit1 = $word;
$tit2 = $word;
$tit2 = substr(strrev($tit2),0,strlen($tit2)-1);
$tit1 = substr(strtoupper($tit1),0,1);
$toolarr2[] = $tit1.$tit2
}
return implode(' ',$toolarr2);
}
[/PHP]

To write it out the textool accepts a string that gives it back capitalized with the first letter of the word and the rest of the word reversed with the last letter cut off.
Feb 28 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.