Title Case in Subject

Started by cosmicxxx, September 28, 2011, 12:38:20 PM

Previous topic - Next topic

MrPhil

mb_convert_case() was introduced with PHP 4.3.0, so if the OP is really way back on 4.1.14, that could explain it. Double check your PHP version, and whether mb_ functions are installed:
<?php phpinfo(); ?>

Arantor

There wasn't a version 4.1.14. If there was, it would have been 10 years ago, and there would be far greater issues with SMF than that.

AMWebby

#22
Thanks guys. Yes, the server is ancient and we're planning a move to a new server. Why didn't I think of php.inf, dih! In the meantime ucwords(strtolower($str)) works. Thanks.

Angelina Belle

In any case, none of these functions can truly achieve the desired title case.
"Mary Had A Little Lamb And She Loved It So" is the best it can do.
To get anything better, you would need, as Mr. Phil pointed out, a language-specific function that knows which are the "important" words that are supposed to be capitalized, and which are the unimportant.  Not only does the dictionary change from language to language, but also the rules for capitalization change (for example -- a lot more words are capitalized in German than in English).  And then -- what about acronyms that also spell words in the current language?  The rules grow more complex with every type of special case.

So this could be a fun learning-to-code exercise, but it will never get even 100% of the way to the desired result.
Unfortunately.

All the best to cosmicxxx, BeatsMe , and AMWebby.  At this time, there is no substitute for human intervention, if you want to enforce "proper" capitalization on your forum.
Never attribute to malice that which is adequately explained by stupidity. -- Hanlon's Razor

Kindred

and what happens if I *WANT* an all caps word in the title?
or, if the proper spelling is all caps or all lower case?
or something like iPod?


You're trying to force your users into something which is likely to be incorrect as much as they are...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Angelina Belle

Different forums.  Different users. Different rules.
In any case -- no matter how appropriate and/or important "title case" might be to a given forum, there is no technical solution available to bring it on.
My suggestion of mb-convert-case.php  was might be the WORST possible proposed semi-solution.
Arantor's is probably much better (because it is going to work on more php installations, even if it doesn't do 100% what the OP wants to do).



Never attribute to malice that which is adequately explained by stupidity. -- Hanlon's Razor

AMWebby

I know I'm resurrecting an old thread but thought it best to stay on topic.

I'm trying to modify the code so that the title case function only works for one particular user. This is my code in Posts.php but it doesn't seem to work.


if ($context['user'] ['id'] == 6)
                {
                 'subject' => ucwords(strtolower($_POST['subject'])),
                }
                else
                {
                'subject' => $_POST['subject'],
                }


Anyone?

Arantor

Where *exactly* in Post.php is that?

AMWebby

Line 1869 on


// Collect all parameters for the creation or modification of a post.
$msgOptions = array(
'id' => empty($_REQUEST['msg']) ? 0 : (int) $_REQUEST['msg'],
// string games
                if ($context['user'] ['id'] == 6)
                {
                 'subject' => ucwords(strtolower($_POST['subject'])),
                }
                else
                {
                'subject' => $_POST['subject'],
                }
                // end string games
'body' => $_POST['message'],
'icon' => preg_replace('~[\./\\\\*:"\'<>]~', '', $_POST['icon']),
'smileys_enabled' => !isset($_POST['ns']),
'attachments' => empty($attachIDs) ? array() : $attachIDs,
'approved' => $becomesApproved,
);

Arantor

Yeah, that's not going to work, you can't just smash an if statement in the middle of another statement. However you can do it this way:

// Collect all parameters for the creation or modification of a post.
$msgOptions = array(
'id' => empty($_REQUEST['msg']) ? 0 : (int) $_REQUEST['msg'],
'subject' => $context['user']['id'] == 6 ? ucwords(strtolower($_POST['subject'])) : $_POST['subject'],
'body' => $_POST['message'],
'icon' => preg_replace('~[\./\\\\*:"\'<>]~', '', $_POST['icon']),
'smileys_enabled' => !isset($_POST['ns']),
'attachments' => empty($attachIDs) ? array() : $attachIDs,
'approved' => $becomesApproved,
);

AMWebby

Ah, my bad. Thanks for the recode.

Advertisement: