Forcing sentence start with Capital letter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

koyauni
Forum Newbie
Posts: 8
Joined: Tue Jun 17, 2008 6:39 pm

Re: Forcing sentence start with Capital letter

Post by koyauni »

I put that ON an sill have problem. But the scrip works for domain without php.ini, I am not so sure what is in php.ini which stop it to work.
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: Forcing sentence start with Capital letter

Post by Stryks »

Firstly, I think you should read and try to understand the suggestions that are offered when you ask a question. The suggestions were not 'drop-in' solutions, but answered your question had you given them a bit of a test. As it is, the solution you found was handed to you earlier on in the thread.

As it happens, I think that a slight modification of the code from JCart is still your best option.

You get your code to a string with punctuation and no capitalization, and you store it in the variable $data. Then ...

Code: Select all

$data = ucfirst(preg_replace_callback('/\A[a-z]|[.?!]\s*([a-z])/i', create_function('$matches', 'return strtoupper($matches[0]);'), $data));


... should do everything for you, including sentences ending in ? or !, regardless of the number of spaces or carriage returns used. This should also take care of paragraphs.

Next, I don't really understand what you are saying your problem is with this error, but did you know that you have used the same variable in two different ways on your example?

Try using ...

Code: Select all

$_POST["ArabicText"]
... in all places where you need to access this value, instead of ...

Code: Select all

$_POST[ArabicText]
Let me know if this helps.
Post Reply