Hello, I have some perl CGI scripts I'm changing over to PHP. I came across these statements in perl and I don't know exactly what they mean and how to convert them to PHP. Can anybody help? $pname = lc($array[1]); $pname = ucfirst($pname); $pname1 = $pname; $pname1 =~ s/ /-/g; Code (markup): What is the lc() function on the first line? What is the ucfirst() function on the second line? Then on line 4 what is ~ s/ /-/g; ? Thanks
Ok I figured out lc() in Perl is strtolower() in PHP and ucfirst() in Perl is the same in PHP. Lower Case = lc() Upper Case First character = ucfirst() But line 4 still has me puzzled.
lc converts a string to lower case, the PHP equivalent is the strtolower() function. ucfirst converts the first letter in each word into upper case. PHP equal is the ucwords function. The third line is a regular expression.... I was never good at those with Perl.
Actually, I think I'm wrong. s/ is a substitute thing. I think it is substituting each space (stuff between the first two slashes) with a dash (stuff between the second two slashes).
Yes, it is searching for spaces, converting them to dashes, and the "g" specifies all possible matches in the string... not just the first one it finds. So I guess the PHP would be: $pname1 = str_replace(' ', '-', $pname1); Code (markup):
I think $pname1 =~ s/ /-/g; is getting the first name, so it is splitting it by the first space or first dash. for php, try: $tmp = preg_split("/[\s\-]/", $pname1); $pname1 = $tmp[0];