ucfirst()

Started by PokémonS, May 25, 2013, 12:49:16 PM

Previous topic - Next topic

PokémonS

SMF 2.0.2

Hi,

I want to change the first character to uppercase in post. It use ucfirst().
http://www.w3schools.com/php/func_string_ucfirst.asp

Can someone give me the code to add ucfirst()?
きみと手をつなごう つらいときはもっと
ゼロからはじめよう ほら ほら 手をつなごう
みんな手をつなごう つらいときはもっと
力を合わせよう ほら ほら 手をつなごう

Kindred

you really just want to piss off your users by "correcting" everything, don't you?

Didn't we talk you out of this silliness months ago?
Сл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."

ARG01

In your index.css, add this to the "body"

text-transform:capitalize;

Should be something like

body {
    background: none repeat scroll 0 0 #131313;
    font: 78%/130% verdana,Helvetica,sans-serif;
    margin: 0;
    padding: 0;
    text-transform:capitalize;
}


Really not sure why you would want to though?  ::)
No, I will not offer free downloads to Premium DzinerStuido themes. Please stop asking.

NanoSector

Quote from: ARG on May 25, 2013, 01:32:07 PM
In your index.css, add this to the "body"

text-transform:capitalize;

Should be something like

body {
    background: none repeat scroll 0 0 #131313;
    font: 78%/130% verdana,Helvetica,sans-serif;
    margin: 0;
    padding: 0;
    text-transform:capitalize;
}


Really not sure why you would want to though?  ::)
Changing The First Letter Of A Word In A Sentence To A Capital Really Is A Way To Piss Me Off. No seriously, for me it goes hand-in-hand with chatspeak.

The OP is asking for a way to capitalise the first word in a sentence, like:
Quotethis sentence is not capitalised
to
QuoteThis sentence is not capitalised
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Kindred

right... because he apparently can't leave his users to post what they want
Сл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."

Chen Zhen

PokémonS,

  You can design your forum any way you wish although altering your users posts may not be prudent.

Edit file: /Sources/Post.php

Find:

// Prepare the message a bit for some additional testing.
$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);



Replace with:

// Prepare the message a bit for some additional testing.
$_POST['message'] = $smcFunc['htmlspecialchars'](sentence_cap($_POST['message']), ENT_QUOTES);


Find at the very end of the file:

?>


Add prior to the above:

function sentence_cap($sentences)
{
$punctuation = array('. ','! ','? ');
$sentences = preg_replace('!\s+!', ' ', $sentences);
foreach ($punctuation as $mark)
{
$text = explode($mark, $sentences);
$newtext = array();
foreach ($text as $sentence)
$newtext[] = ucfirst($sentence);

$sentences = implode($mark, $newtext);
}

return $sentences;
}


.. this will capitalize every sentence.

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Advertisement: