Topic: regex - capitalize what's inside parenthesis (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=28375" title="Pages that link to Topic: regex - capitalize what&amp;#039;s inside parenthesis (Page 1 of 1)" rel="nofollow" >Topic: regex - capitalize what&#039;s inside parenthesis <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 08-31-2006 21:52

Greets!

I am using

code:
echo ucwords(strtolower($pageTITLE));


to format the title of a page. However, some titles have things in parenthesis, such as
Program Electronic Review Management (PERM)
but, using my format, ends up as
Program Electronic Review Management (perm)
How can I use ucwords to capitalize the content in the parenthesis?

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 09-01-2006 13:32
code:
preg_replace_callback ( "~\([^ A-Z)]+\)", my_func, $str, FUNNY_MATCH__FLAG_LOOK_IT_UP );

my_func ( $matches )
{
  return uppercase $matches[0];
}

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 09-26-2006 20:07

Alright - I was noodling with this finally, and I'm still having a problem with it. If I try

code:
<?php
$str = "cool stuff (blah)";
function my_func($matches){
	return ucwords($matches[0]);
}
echo preg_replace_callback("~\([^ A-Z)]+\)~", my_func, $str);
?>



The text in the parenthesis, "blah", is all lower case. If I change the ucwords($matches) to strtoupper($matches), I get "BLAH".

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 09-26-2006 20:33

Ay it's not recognizing (blah) as a word, it needs to start alphabetic - really it's breaking for the same reason the first solution did..

Try

code:
<?php
$str = "cool stuff (blah)";
function my_func($matches){
	return "(".ucwords($matches[1]).")";
}
echo preg_replace_callback("~\(([^ A-Z)]+)\)~", my_func, $str);
?>





.:[ Never resist a perfect moment ]:.

(Edited by bitdamaged on 09-27-2006 03:03)



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu