This topic is locked

Proper Case - v3.1

9/18/2006 12:00:59 PM
PHPRunner General questions
M
mmponline author

Is there an easy way to change data to show proper case like the Upper case functon in v3.1
Proper case like name bill gates becomes Bill Gates. The sample code that is supplied on the xlinsoft.com site gives an error if inserted under events.
The 3.1 template editor has this: $value=strtoupper($value); for uppercase under custom code.
What would work for proper case?
Where can I find other helpful code snippets?

R
RickG 9/18/2006

I would experiment and change this to:
$value=ucwords($value);
which should work. More info at http://www.php.net/manual/en/function.ucwords.php
Hope this helps -

M
mmponline author 9/18/2006

This works fine, thanks RickG.
It wont, however change ALL CAPS to Proper Case, but that's not to serious. At least lower case will be fixed.
Thanks again for your help!

R
RickG 9/18/2006

Welcome ...
If it really becomes an issue (with entries in all upper case) you could use both. There are a couple of examples in the link page where it looks like folks are first passing the value to strtolower (to get it all in lower case) and then taking the result and passing it against ucwords to get the final result. I'm sure with a little tweaking you could modify the code to follow the same behavior.

Sergey Kornilov admin 9/18/2006

Here is the piece of code that does the job. It understands phrases as well as single words:

$str = $values["UserName"];
for ($i=0; $i<strlen($str); $i++)

{

if ($i==0)

$b = True;

else

$b = (substr($str, $i-1,1) == " ");

if ($b)

$str = substr($str,0,$i).strtoupper(substr($str, $i,1)).substr($str, $i+1);

else

$str = substr($str,0,$i).strtolower(substr($str, $i,1)).substr($str, $i+1);

}
$values["UserName"] = $str;
M
mmponline author 9/19/2006

Sergey
Thanks for the code example. I prosume the "Username" value must be replaced with the specific field. Eg. "position"
Q. Can this code be used in the custom code of the specific field (V3.1 on the Visual editor's properties) or do I need to include it in the events for that specific page?

Alexey admin 9/19/2006

Stephan,
this code is for events.

Also you can use the same code for Custom View type in Visual Editor.

K
ke5rs 10/4/2006

Hi

I have a strange problem with Proper Case and my fields.

The very first letter is ignored but if I put a space in front, then it works fine keeping the space.
Example

'ST. PAUL' returns 'st. Paul'

and

' ST. PAUL' returns ' St. Paul'
Both Sergey's code below and

$values['city']=ucwords(strtolower($values['city']))

get the same thing.
Any idea's

John

Here is the piece of code that does the job. It understands phrases as well as single words:


$str = $values["UserName"];
for ($i=0; $i<strlen($str); $i++)

{

if ($i==0)

$b = True;

else

$b = (substr($str, $i-1,1) == " ");

if ($b)

$str = substr($str,0,$i).strtoupper(substr($str, $i,1)).substr($str, $i+1);

else

$str = substr($str,0,$i).strtolower(substr($str, $i,1)).substr($str, $i+1);

}
$values["UserName"] = $str;
Alexey admin 10/5/2006

John,
the posted code works fine with the both 'ST. PAUL' and ' ST. PAUL' values.
Debug your event code by your own or post it here and I'll try to help you.

K
ke5rs 10/8/2006

Hello Sergey

Here is my code from tablename_events.php

The 'call' field works fine retuning all caps but the propercase returns all lower case except if I put a space in front.
<?php
function BeforeAdd(&$values)

{

$values['call']=strtoupper($values['call']);

$values['city']=ucwords(strtolower($values['city']));

$values['county']=ucwords(strtolower($values['county']));

return true;

}
function BeforeEdit(&$values, $where)

{

$values['call']=strtoupper($values['call']);

$values['city']=ucwords(strtolower($values['city']));

$values['county']=ucwords(strtolower($values['county']));

return true;

}
?>

//***8end of my code****

John,

the posted code works fine with the both 'ST. PAUL' and ' ST. PAUL' values.
Debug your event code by your own or post it here and I'll try to help you.

Alexey admin 10/9/2006

Hi,
you can use the following code instead of:

$str = strtolower($values['city']);

for ($i=0; $i<strlen($str); $i++)

{

if ($i==0)

$b = True;

else

$b = (substr($str, $i-1,1) == " ");

if ($<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=11696&image=1&table=forumreplies' class='bbc_emoticon' alt='B)' />

$str = substr($str,0,$i).strtoupper(substr($str, $i,1)).substr($str, $i+1);

else

$str = substr($str,0,$i).strtolower(substr($str, $i,1)).substr($str, $i+1);

}

$values['city'] = $str;

instead of:

$values['city']=ucwords(strtolower($values['city']));



to fix this issue.

K
ke5rs 10/13/2006

Hi Alexey

Ther code below you suggest too did not fix the problem. It behaves exactly like simple one liner code.
'ST. PAUL' returns 'st. Paul'

and

' ST. PAUL' returns ' St. Paul'
My fields are defined 'varchar' if that means anything.
John

Hi,

you can use the following code instead of:

instead of:
to fix this issue.

Alexey admin 10/16/2006

Hi,
both the ucwords function and our code work properly.
I suppose you have another portion of code somewhere else that coverts 'St. Paul' to 'st. Paul'.