You are here:  » All lower case normalise function?


All lower case normalise function?

Submitted by webman on Wed, 2006-11-08 13:13 in

Hi David,

Currently PT normalise cpitalises the first character of a name field. Is there a way to add an additional normalise function that creates all lower case characters?

Many Thanks

Les :)

Submitted by support on Wed, 2006-11-08 13:17

Hi Les,

You could quickly add a new filter to provide a strtolower function, and then register this against the product name field. Here's the code - simply paste it into includes/filter.php:

<?php
  
/*************************************************/
  /* strToLower                                    */
  /*************************************************/
  
$filter_names["strToLower"] = "strToLower";
  function 
filter_strToLowerConfigure($filter_data)
  {
    print 
"<p>There are no additional configuration parameters for this filter.</p>";
  }
  function 
filter_strToLowerValidate($filter_data)
  {
  }
  function 
filter_strToLowerExec($filter_data,$text)
  {
    return 
strtolower($text);
  }
?>

Hope this helps!
David.

Submitted by chrisst1 on Mon, 2012-06-18 11:09

Morning David

I'm using the above filter and replaced

return strtolower($text);

with

return ucfirst(strtolower($text));

which works fine for the first sentence. Is it possible to upper case for each new sentence after a full stop with this filter.

Cheers

Chris

Submitted by support on Mon, 2012-06-18 11:32

Hi Chris,

I think you would need to split the text up into sentences; ucfirst() each sentence and then re-join. Straight forward to do - rather the modify the above here's the code for a new filter "Sentence Case":

  /*************************************************/
  /* sentenceCase */
  /*************************************************/
  $filter_names["sentenceCase"] = "Sentence Case";
  function filter_sentenceCaseConfigure($filter_data)
  {
    print "<p>There are no additional configuration parameters for this filter.</p>";
  }
  function filter_sentenceCaseValidate($filter_data)
  {
  }
  function filter_sentenceCaseExec($filter_data,$text)
  {
    $text = strtolower($text);
    $sentences = explode(".",$text);
    foreach($sentences as $k => $v)
    {
      $v = trim($v);
      $sentences[$k] = ucfirst($v);
    }
    return implode(". ",$sentences).".";
  }

Cheers,
David.
--
PriceTapestry.com