Menu
Using this function, How can I get it so that it will uppercase the first letter after a parentheses, (a cat) would become (A Cat), and not (a Cat).
[code=php]
function ucFirstWithParenthesis($string){
$temp = str_replace("(","( ",$string);
$temp = ucwords($temp);
return $temp;
}
[/code]
[code=php]function edit_name($edit){
$nedit = str_replace("(","( ",$edit);
$temp = ucwords($nedit);
$nedit = str_replace("( ","(",$temp);
return $nedit;
}[/code]
[code=php]<?php
$target = 'a (string with brackets).';
echo preg_replace('/b[a-z]/e', "strtoupper('$0')", $target);
?>[/code]
So... If I would like to uppercase the letter after a period would I use this:No! For a start an unescaped dot in PCRE is a wildcard. Also even if it were an escaped dot all you would be capturing would be a dot.
preg_replace('/b./e', "strtoupper('$0')", $target);[/QUOTE]
And if I would like to uppercase the letter after a hyphen would I use this:All you are capturing here is a hyphen.
preg_replace('/b-/e', "strtoupper('$0')", $target);[/QUOTE]
[code=php]$nedit = preg_replace('/b[a-z]/e', "strtoupper('$0')", $nedit);[/code]
[code=php]$nedit = preg_replace('/(?<!')b[a-z]/e', "strtoupper('$0')", $nedit);[/code]
[code=php]$nedit = preg_replace('/(?<![a-z]')b[a-z]/e', "strtoupper('$0')", $nedit);[/code]
That doesn't do it, it still makes everything after a [B]'[/B] uppercase[/QUOTE]You said you wanted
[code=php]<?php
$nedit = "don't! rock 'n roll!";
echo $nedit = preg_replace('/(?<![a-z]')b[a-z]/e', "strtoupper('$0')", $nedit);
# echos: Don't! Rock 'N Roll!
?>[/code]
What is the problem with that? Isn't that what you asked for?[code=php]function move_end($text)
{
return(preg_replace('/^(a|an|the)s+(.+)/i', '\2, \1', $text));
}
function edit_name($edit){
$remove = array("/", "&", " ");
$replace = array("", "And", " ");
$nedit = move_end(ucwords(addslashes(strtolower(str_replace($remove,$replace,$edit)))));
$nedit = str_replace(".",". ",$nedit);
$temp = ucwords($nedit);
$nedit = str_replace(". ",".",$temp);
$nedit = str_replace("-","- ",$nedit);
$temp = ucwords($nedit);
$nedit = str_replace("- ","-",$temp);
$nedit = preg_replace('/(?<![a-z]')b[a-z]/e', "strtoupper('$0')", $nedit);
return $nedit;
}[/code]
[code=php]function edit_name($nedit)
{
$nedit = strtolower($nedit);
$nedit = str_replace(array("/", "&", " "), array("", "and", " "), $nedit);
$nedit = preg_replace('/^(a|an|the)s+(.+)/i', '$2, $1', $nedit);
$nedit = preg_replace('/(?<![a-z]')b[a-z]/e', "strtoupper('$0')", $nedit);
return addslashes($nedit);
}[/code]
"[I]Nope, that doesn't work for me.[/I]" That type of statement is not very helpful to your cause. Provide the string that is problematic, the expected result and the obtained result.[/QUOTE]
[code=php]<?php
function edit_name($nedit)
{
$nedit = strtolower($nedit);
$nedit = str_replace(array("/", "&", " "), array("", "and", " "), $nedit);
$nedit = preg_replace('/^(a|an|the)s+(.+)/i', '$2, $1', $nedit);
$nedit = preg_replace('/(?<![a-z]')b[a-z]/e', "strtoupper('$0')", $nedit);
return addslashes($nedit);
}
$tests = array("don't! rock 'n roll",
"l'esprit d'escalier",
"'bout",
"that's",
"one-x",
"l.d.n."
);
foreach($tests as $test)
{
echo edit_name($test)."<br>n";
}
?>[/code]
0.1.9 — BETA 5.19