Not first word of titles

sbj

Well-known member
Hello, I have a php script to modify the titles of threads (to uppercase all words).
It works fine but I want to add exceptional words to the list, which should stay in all cases lowercase, except if it is the first word of the title.

Now this code is working fine, but the problem is

PHP:
if (substr_count($title, 'Ve') > 0){
    $patterns[0] = '/\bVe\b/';
    $replacements[0] = 've';
    $title = preg_replace($patterns, $replacements, $title);
}

that all words "Ve" become to "ve". But obviously the first letter of the title should always be in Uppercase.
How can I add an exception to this rule like "NOT FIRST WORD?

PHP:
if (substr_count($title, 'Ve') > 0 $$ NOT FIRST WORD){
    $patterns[0] = '/\bVe\b/';
    $replacements[0] = 've';
    $title = preg_replace($patterns, $replacements, $title);
}
 
With my limited knowledge I did a workaround.



PHP:
//the word "Ve" is the example word I want to stay in all cases lowercase except if it is the first word of title.

if (substr_count($title, 'Ve') > 0){
    //save the first word
    $arr = explode(' ',trim($title));
 
    //cut the first word
    $title = substr(strstr($title," "), 1);
 
    //match the exact word you want to stay lowercase in the rest of the title
    $patterns[0] = '/\bVe\b/';
    $replacements[0] = 've';
    $title = preg_replace($patterns, $replacements, $title);
 
    // saved first word + updated rest of title.
    $title = $arr[0] . ' ' .  $title;
}
 
Last edited:
Top Bottom