Forcing sentence start with Capital letter
Moderator: General Moderators
Forcing sentence start with Capital letter
I am making a auto conversion from Arabic script into Latin. Users will be able to cut and past Arabic based text into text area and click convert. I have made it work accept for one crucial thing. Since in Arabic based alphabet there is no distinguish between small and capital letters I am having problem to force the converted sentences starting with capital letters. I appreciate any help in this regard.
Project is based at
http://kurdan.org/converter/arablatin.php
An example such as
(... ئهستهمترین ئهگهرهکانی. فهرههنگی) => will become (... estemtirín egerekaní. ferhengí)
I want that the word ferhengí or any word after (.) starts with a capital letter in this case . Ferhangí
Thanks
Project is based at
http://kurdan.org/converter/arablatin.php
An example such as
(... ئهستهمترین ئهگهرهکانی. فهرههنگی) => will become (... estemtirín egerekaní. ferhengí)
I want that the word ferhengí or any word after (.) starts with a capital letter in this case . Ferhangí
Thanks
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Forcing sentence start with Capital letter
Code: Select all
$data = ucfirst(preg_replace_callback('#\.\s([a-z])#i', create_function('$matches', 'return strtoupper($matches[0]);'), $data));Re: Forcing sentence start with Capital letter
If you need just the first word capital , use
ucfirst("estemtirín egerekaní. ferhengí") = "Estemtirín egerekaní. ferhengí"
If you want every word to start with capital you should use
ucwords("estemtirín egerekaní. ferhengí") = "Estemtirín Egerekaní. Ferhengí"
EDIT: If you want sentences to start with a capital letter.
Something like:
That should work.
Sam
ucfirst("estemtirín egerekaní. ferhengí") = "Estemtirín egerekaní. ferhengí"
If you want every word to start with capital you should use
ucwords("estemtirín egerekaní. ferhengí") = "Estemtirín Egerekaní. Ferhengí"
EDIT: If you want sentences to start with a capital letter.
Something like:
Code: Select all
$sentence = explode(".", "estemtirín egerekaní. ferhengí");
//sentence[0] = estemtirín egerekaní
//sentence[1] = ferhengí
$output = implode(". ", ucfirst($sentence));
//$output = Estemtirín egerekaní. Ferhengí
Sam
Last edited by helraizer on Tue Jun 17, 2008 8:02 pm, edited 1 time in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Forcing sentence start with Capital letter
Neither of those fit his requirement. He needs the first letter of the first word after a period to be capatalized.helraizer wrote:If you need just the first word capital , use
ucfirst("estemtirín egerekaní. ferhengí") = "Estemtirín egerekaní. ferhengí"
If you want every word to start with capital you should use
ucwords("estemtirín egerekaní. ferhengí") = "Estemtirín Egerekaní. Ferhengí"
Re: Forcing sentence start with Capital letter
Yeah, I realised that, that's why I added the EDIT.Jcart wrote:Neither of those fit his requirement. He needs the first letter of the first word after a period to be capatalized.helraizer wrote:If you need just the first word capital , use
ucfirst("estemtirín egerekaní. ferhengí") = "Estemtirín egerekaní. ferhengí"
If you want every word to start with capital you should use
ucwords("estemtirín egerekaní. ferhengí") = "Estemtirín Egerekaní. Ferhengí"
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Forcing sentence start with Capital letter
You cannot pass an array to ucfirst, therefore you'll need to apply a callback to the array.. which is almost exactly what I demonstrated.helraizer wrote:Code: Select all
$sentence = explode(".", "estemtirín egerekaní. ferhengí"); //sentence[0] = estemtirín egerekaní //sentence[1] = ferhengí $output = implode(". ", ucfirst($sentence)); //$output = Estemtirín egerekaní. Ferhengí
Re: Forcing sentence start with Capital letter
Thank you guys,
The sentence I posted here was just an example. I want every intial letter after last full stop (.) start a Capital letter.
This is just a sentence I am posting here. Capital letter should appear here.
The sentence I posted here was just an example. I want every intial letter after last full stop (.) start a Capital letter.
This is just a sentence I am posting here. Capital letter should appear here.
Re: Forcing sentence start with Capital letter
Jcart's first code will do just that.koyauni wrote:Thank you guys,
The sentence I posted here was just an example. I want every intial letter after last full stop (.) start a Capital letter.
This is just a sentence I am posting here. Capital letter should appear here.
Re: Forcing sentence start with Capital letter
Thanks,
I did that but there is no action,
I have created a file aphabet.php where I do all convention and in anther file I display the results as
$ArabicText = $_POST['ArabicText'];
# Substitutions
include ("alphabet.php");
$StageOne = strtr($ArabicText, $alphabet);
$StageTwo = strtr($StageOne, $alphabet2);
$StageThree = strtr($StageTwo, $alphabet3);
$StageFour = strtr ($StageThree, $alphabet4);
Where should I add this function to be included? Do I have to define the type $data?
I did that but there is no action,
I have created a file aphabet.php where I do all convention and in anther file I display the results as
$ArabicText = $_POST['ArabicText'];
# Substitutions
include ("alphabet.php");
$StageOne = strtr($ArabicText, $alphabet);
$StageTwo = strtr($StageOne, $alphabet2);
$StageThree = strtr($StageTwo, $alphabet3);
$StageFour = strtr ($StageThree, $alphabet4);
Where should I add this function to be included? Do I have to define the type $data?
Re: Forcing sentence start with Capital letter
I manged to do this by
create array as
'. a' => '. A',
for every single letter of the alphabet. I know is not pragmatically smart way to do but it is working.
One issue which has make it hard for me is that in conversion process where in the initial text there is st sign " a \ is implemented and think this is the default PHP way of seeing the sign " ,
Is there any way to stop PHP doing that insertion?
A test like
Arabic text Arabic text Arabic text "Arabic text" Arabic text Arabic text.
after conversation become
Latin text Latin text Latin text \"Latin text\" Latin text Latin text.
I do not need the back slash \ in converted text.
create array as
'. a' => '. A',
for every single letter of the alphabet. I know is not pragmatically smart way to do but it is working.
One issue which has make it hard for me is that in conversion process where in the initial text there is st sign " a \ is implemented and think this is the default PHP way of seeing the sign " ,
Is there any way to stop PHP doing that insertion?
A test like
Arabic text Arabic text Arabic text "Arabic text" Arabic text Arabic text.
after conversation become
Latin text Latin text Latin text \"Latin text\" Latin text Latin text.
I do not need the back slash \ in converted text.
Re: Forcing sentence start with Capital letter
That's PHP protecting itself. Or you used mysql_real_escape_string or addslashes. If you had a text field and wrote "> then you could inject HTML and script into the site (for that time, not perminant). Use:koyauni wrote:I manged to do this by
create array as
'. a' => '. A',
for every single letter of the alphabet. I know is not pragmatically smart way to do but it is working.
One issue which has make it hard for me is that in conversion process where in the initial text there is st sign " a \ is implemented and think this is the default PHP way of seeing the sign " ,
Is there any way to stop PHP doing that insertion?
A test like
Arabic text Arabic text Arabic text "Arabic text" Arabic text Arabic text.
after conversation become
Latin text Latin text Latin text \"Latin text\" Latin text Latin text.
I do not need the back slash \ in converted text.
Code: Select all
$arabic_text = stripslashes($arabic_text);
Re: Forcing sentence start with Capital letter
Thank you it worked prefect.
I have solved the problem with the capital letter at the start of sentence. Now what if the world is the start of a paragraph? How do make the first letter of the paragraph a capital letter?
I have solved the problem with the capital letter at the start of sentence. Now what if the world is the start of a paragraph? How do make the first letter of the paragraph a capital letter?
Re: Forcing sentence start with Capital letter
I found answer at
http://uk3.php.net/ucfirst
Another way to capitalize first letter of every sentence in a text, I hope it will help someone. It won't convert non-English characters, though, and ignores sentences ending with ! or ? etc.
<?php
$text="this is a sentence. this is another sentence.";
$split=explode(". ", $text);
foreach ($split as $sentence) {
$sentencegood=ucfirst($sentence);
$text=str_replace($sentence, $sentencegood, $text);
}
echo $text; // This is a sentence. This is another sentence.
?>
http://uk3.php.net/ucfirst
Another way to capitalize first letter of every sentence in a text, I hope it will help someone. It won't convert non-English characters, though, and ignores sentences ending with ! or ? etc.
<?php
$text="this is a sentence. this is another sentence.";
$split=explode(". ", $text);
foreach ($split as $sentence) {
$sentencegood=ucfirst($sentence);
$text=str_replace($sentence, $sentencegood, $text);
}
echo $text; // This is a sentence. This is another sentence.
?>
Re: Forcing sentence start with Capital letter
I have a php.ini on my server with - register_globals = Off which appernetly do not allow for POST variable to work as
<textarea ><? print ($_POST["ArabicText"]) ?></textarea> // value in the form is picked up by this
if(isset($_POST[ArabicText])) { // called up here
$ArabicText = stripslashes($ArabicText);
Any idea how I can work around this without setting Gregister ON which makes Drupal 6.2 unstable?
<textarea ><? print ($_POST["ArabicText"]) ?></textarea> // value in the form is picked up by this
if(isset($_POST[ArabicText])) { // called up here
$ArabicText = stripslashes($ArabicText);
Any idea how I can work around this without setting Gregister ON which makes Drupal 6.2 unstable?