Jump to content


Help on Upercase


13 replies to this topic

#1 Mr. Jay

    Young Padawan

  • Members
  • Pip
  • 81 posts

Posted 22 January 2007 - 01:25 AM

Trying to make get the text to Upercase after typing (! . ?)

Example:

Quote

hello!!! how are you doing?
to
Hello!!! How are you doing?
I tried ucfirst but it only returns as

Quote

Hello!!! how are you doing?


#2 bay

    Young Padawan

  • Members
  • Pip
  • 105 posts
  • Gender:Male
  • Location:Chicago, IL USA

Posted 22 January 2007 - 03:43 AM

Ok, this isn't the most conventional method probably, but its 2:42 AM and I want to go to bed.

What you can do is explode the string into an array and check each character to be a ? or ! and then rebuild the string with the letter that follows uppercased.

Or, you can use string offset and compare each character, which is essentially the same thing..idk, maybe some regex could do the trick, my brain is fried right now zzz

#3 cigraphics

    Young Padawan

  • Members
  • Pip
  • 89 posts
  • Gender:Male
  • Location:Pitesti, Romania

Posted 22 January 2007 - 07:57 AM

try with css

<style>
.up {
text-transform:capitalize;
}
</style>

<span class="up">hello world</span>

#4 bay

    Young Padawan

  • Members
  • Pip
  • 105 posts
  • Gender:Male
  • Location:Chicago, IL USA

Posted 22 January 2007 - 06:31 PM

Heh, this is a neat way to do it, explode the string based on your punctuation, and then you can use ucwords to capitalize each part, and then you can implode it, or rebuild the string with loops :) Kinda creative, do what you want, there's multiple ways.

#5 Mr. Jay

    Young Padawan

  • Members
  • Pip
  • 81 posts

Posted 22 January 2007 - 10:25 PM

Still need help

#6 bay

    Young Padawan

  • Members
  • Pip
  • 105 posts
  • Gender:Male
  • Location:Chicago, IL USA

Posted 23 January 2007 - 12:40 AM

I listed 2 methods that you could achieve your result, did you even attempt them?

Post what you have done so far that its easier for us to help, and for you to learn, otherwise you aren't learning at all.

#7 Mr. Jay

    Young Padawan

  • Members
  • Pip
  • 81 posts

Posted 23 January 2007 - 03:31 AM

View Postbay, on Jan 22 2007, 11:40 PM, said:

I listed 2 methods that you could achieve your result, did you even attempt them?

Post what you have done so far that its easier for us to help, and for you to learn, otherwise you aren't learning at all.
I know how to do loops & ucwords, but not implode/explode. Thats why I came to the help section, since I dont know how..

#8 dEcade

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 1,850 posts
  • Gender:Male
  • Location:Saskatoon, Saskatchewan
  • Interests:Guitar, Programming, Storm Chasing, Games (Designing and playing), Hockey, Photography

Posted 23 January 2007 - 05:39 PM

I don't know if these will help you at all.

Explode - http://ca3.php.net/m...ion.explode.php

Implode - http://ca3.php.net/m...ion.implode.php

dEcade

#9 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 23 January 2007 - 11:54 PM

View Postcigraphics, on Jan 22 2007, 06:57 AM, said:

try with css

<style>
.up {
text-transform:capitalize;
}
</style>

<span class="up">hello world</span>

i like this way. :)


don't actually do it except by CSS looks. :D

#10 Mr. Jay

    Young Padawan

  • Members
  • Pip
  • 81 posts

Posted 24 January 2007 - 03:11 AM

Tell me what I did wrong

<?php
$before = 'hello! how are you doing? lolz!';
$punct = array("!", ".", "?");
$array = ucfirst(explode($punct, $before, -1));
$after = implode(",", $array);
echo $after;
?>

Still need help

#11 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 26 January 2007 - 01:21 AM

explode() ruturns an array and accepts only strings for paramaters (not arrays). ucfirst() accepts only a string as a paramater, not an array.
<?php
$before = 'hello! how are you doing? lolz!';
$array = explode('!', $before);
while(list($key,$string) = each($array)){
	$new_array[] = explode('.', $string);
}

$array = array();
while(list($key,$ar) = each($new_array)){
	while(list($k,$string) = each($ar)){
		$array[] = explode('?', $string);
	}
}

$after = implode(",", $array);
echo $after;
?>
I wish i could think of a more recursive way to do that, but none come to mind. Since i haven't tested it, i say good luck and let us know how it turns out.

#12 Mr. Jay

    Young Padawan

  • Members
  • Pip
  • 81 posts

Posted 26 January 2007 - 05:40 AM

Returns up like this

Quote

Array,Array,Array


#13 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 26 January 2007 - 02:00 PM

You don't do much php work do you?
while(list($key,$ar) = each($array)){
	$array2[] = implode(',', $array);
}

$after = implode(",", $array2);
Try that.

#14 bay

    Young Padawan

  • Members
  • Pip
  • 105 posts
  • Gender:Male
  • Location:Chicago, IL USA

Posted 29 January 2007 - 06:20 PM

<?php

function formatSentence ( $str )
{
	preg_match_all ( '/.*?(\.|\?|!)/', $str, $abc ); // you may need to edit this if you have any other punctuation you want to check for

	foreach ( $abc[0] as $a )
	{
		$rebuilt .= strlen ( $a ) == 1 ? '' : ' ';
		$rebuilt .= ucfirst ( trim ( $a ) );
	}
	
	$rebuilt = substr ( $rebuilt, 1 );
	return $rebuilt;
}

$str = 'hi. my Name is bay!! this is not capitalized!?! BUT THIS IS. woW!';
echo formatSentence ( $str );

?>

That's something i whipped up real quick because I had a minute after school. Might not be the most conventional/efficient, but it works.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users