473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Perl to PHP conversion

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
1 963
xwero
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

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

Similar topics

1
by: Edward WIJAYA | last post by:
Hi, I am new to Python, and I like to learn more about it. Since I am used to Perl before, I would like to know what is Python equivalent of Perl code below: $filename = $ARGV;
11
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © # the "filter" function can be used to © # reduce a list such that unwanted © # elements are removed. © # example: © © def even(n): return n % 2 == 0...
0
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © # once a module is loaded © # import mymodule © # one can find all the names it © # export with dir() © © import sys © print dir(sys)
4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
2
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © # in Python, one can define a boxed set © # of data and functions, which are © # traditionally known as "class". © © # in the following, we define a...
3
by: Chris Pruett | last post by:
An odd (to me) behavior I was hoping someone could explain. Take the simple command: perl -e 'print 0xCEC5 + 0xFFFFE253 & 0xFFFF' I tried this on a number of computers. Most give 0xFFFF, ...
1
by: Dark | last post by:
Im trying to insert a clob into the database and I get the following error. DBD::DB2::st execute failed: SQL0804N The application program input parameters for the current request are not...
3
by: mdaetwyler | last post by:
Hi all I am trying to call a DB/2 v8.2 stored procedure from Perl DBI and am getting an error message telling me, that the routine could not be found in the library path. SQL0444N Routine...
2
by: jeffrey.bigham | last post by:
Hello, I'm writing a program that needs to read input line by line and analyze each, and it needs to be as efficient as possible. I wrote the following sample program that works, but is 10...
12
by: rurpy | last post by:
Is there an effcient way (more so than cgi) of using Python with Microsoft IIS? Something equivalent to Perl-ISAPI?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.