php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #8328 ucwords and ucfirst misbehaving with quotes
Submitted: 2000-12-20 01:03 UTC Modified: 2003-01-18 10:32 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: vitaliyf at gameaholic dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.0.3pl1 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2000-12-20 01:03 UTC] vitaliyf at gameaholic dot com
Another unrelated ucwords/ucfirst bug(?):

<?php
  $string = 'this is a "test" with word "test" in quotes';
  print ucwords($string);
  $string = '"test2" again';
  print ucfirst($string);
?>

produces:

This Is A "test" With Word "test" In Quotes
"test2" Again

I understand that by algorithm, first character of each word *IS* upper-cased (because first character is ").  However, for us humans, " is not considered a part of a word, therefore "t" in above example should be treated as first letter, and test and test2 should be Test and Test2.

I think that any non-alphanumeric character that is in the beginning of a word (meaning follows a whitespace) should not be considered as "first".

So then:

"test1" - 'test2'   would be    "Test1" - 'Test2'
"test3" -'test4'    would be    "Test3" -'Test4'
"test5-test6"       would be    "Test5-test6"

Comments welcome..

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-10 01:37 UTC] david@php.net
i disagree with the proposed change to ucfirst (which incidentally returns >>"test2" again<<) since, unlike ucwords, it isn't necessarily only used for natural language.
 [2003-01-18 10:32 UTC] moriyoshi@php.net
FYI: you can use mb_convert_case() function that was introduced in 4.3.0 instead of ucwords(). It works exactly as you want.



 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC