当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_String::stripSpaces方法代码示例

本文整理汇总了PHP中CRM_Utils_String::stripSpaces方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_String::stripSpaces方法的具体用法?PHP CRM_Utils_String::stripSpaces怎么用?PHP CRM_Utils_String::stripSpaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_String的用法示例。


在下文中一共展示了CRM_Utils_String::stripSpaces方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parseStreetAddress

 /**
  * Parse given street address string in to street_name,
  * street_unit, street_number and street_number_suffix
  * eg "54A Excelsior Ave. Apt 1C", or "917 1/2 Elm Street"
  *
  * NB: civic street formats for en_CA and fr_CA used by default if those locales are active
  *     otherwise en_US format is default action
  *
  * @param string $streetAddress
  *   Street address including number and apt.
  * @param string $locale
  *   Locale used to parse address.
  *
  * @return array
  *   parsed fields values.
  */
 public static function parseStreetAddress($streetAddress, $locale = NULL)
 {
     $config = CRM_Core_Config::singleton();
     /* locales supported include:
      *  en_US - http://pe.usps.com/cpim/ftp/pubs/pub28/pub28.pdf
      *  en_CA - http://www.canadapost.ca/tools/pg/manual/PGaddress-e.asp
      *  fr_CA - http://www.canadapost.ca/tools/pg/manual/PGaddress-f.asp
      *          NB: common use of comma after street number also supported
      *  default is en_US
      */
     $supportedLocalesForParsing = array('en_US', 'en_CA', 'fr_CA');
     if (!$locale) {
         $locale = $config->lcMessages;
     }
     // as different locale explicitly requested but is not available, display warning message and set $locale = 'en_US'
     if (!in_array($locale, $supportedLocalesForParsing)) {
         CRM_Core_Session::setStatus(ts('Unsupported locale specified to parseStreetAddress: %1. Proceeding with en_US locale.', array(1 => $locale)), ts('Unsupported Locale'), 'alert');
         $locale = 'en_US';
     }
     $emptyParseFields = $parseFields = array('street_name' => '', 'street_unit' => '', 'street_number' => '', 'street_number_suffix' => '');
     if (empty($streetAddress)) {
         return $parseFields;
     }
     $streetAddress = trim($streetAddress);
     $matches = array();
     if (in_array($locale, array('en_CA', 'fr_CA')) && preg_match('/^([A-Za-z0-9]+)[ ]*\\-[ ]*/', $streetAddress, $matches)) {
         $parseFields['street_unit'] = $matches[1];
         // unset from rest of street address
         $streetAddress = preg_replace('/^([A-Za-z0-9]+)[ ]*\\-[ ]*/', '', $streetAddress);
     }
     // get street number and suffix.
     $matches = array();
     //alter street number/suffix handling so that we accept -digit
     if (preg_match('/^[A-Za-z0-9]+([\\S]+)/', $streetAddress, $matches)) {
         // check that $matches[0] is numeric, else assume no street number
         if (preg_match('/^(\\d+)/', $matches[0])) {
             $streetNumAndSuffix = $matches[0];
             // get street number.
             $matches = array();
             if (preg_match('/^(\\d+)/', $streetNumAndSuffix, $matches)) {
                 $parseFields['street_number'] = $matches[0];
                 $suffix = preg_replace('/^(\\d+)/', '', $streetNumAndSuffix);
                 $parseFields['street_number_suffix'] = trim($suffix);
             }
             // unset from main street address.
             $streetAddress = preg_replace('/^[A-Za-z0-9]+([\\S]+)/', '', $streetAddress);
             $streetAddress = trim($streetAddress);
         }
     } elseif (preg_match('/^(\\d+)/', $streetAddress, $matches)) {
         $parseFields['street_number'] = $matches[0];
         // unset from main street address.
         $streetAddress = preg_replace('/^(\\d+)/', '', $streetAddress);
         $streetAddress = trim($streetAddress);
     }
     // suffix might be like 1/2
     $matches = array();
     if (preg_match('/^\\d\\/\\d/', $streetAddress, $matches)) {
         $parseFields['street_number_suffix'] .= $matches[0];
         // unset from main street address.
         $streetAddress = preg_replace('/^\\d+\\/\\d+/', '', $streetAddress);
         $streetAddress = trim($streetAddress);
     }
     // now get the street unit.
     // supportable street unit formats.
     $streetUnitFormats = array('APT', 'APARTMENT', 'BSMT', 'BASEMENT', 'BLDG', 'BUILDING', 'DEPT', 'DEPARTMENT', 'FL', 'FLOOR', 'FRNT', 'FRONT', 'HNGR', 'HANGER', 'LBBY', 'LOBBY', 'LOWR', 'LOWER', 'OFC', 'OFFICE', 'PH', 'PENTHOUSE', 'TRLR', 'TRAILER', 'UPPR', 'RM', 'ROOM', 'SIDE', 'SLIP', 'KEY', 'LOT', 'PIER', 'REAR', 'SPC', 'SPACE', 'STOP', 'STE', 'SUITE', 'UNIT', '#');
     // overwriting $streetUnitFormats for 'en_CA' and 'fr_CA' locale
     if (in_array($locale, array('en_CA', 'fr_CA'))) {
         $streetUnitFormats = array('APT', 'APP', 'SUITE', 'BUREAU', 'UNIT');
     }
     //@todo per CRM-14459 this regex picks up words with the string in them - e.g APT picks up
     //Captain - presuming fixing regex (& adding test) to ensure a-z does not preced string will fix
     $streetUnitPreg = '/(' . implode('|\\s', $streetUnitFormats) . ')(.+)?/i';
     $matches = array();
     if (preg_match($streetUnitPreg, $streetAddress, $matches)) {
         $parseFields['street_unit'] = trim($matches[0]);
         $streetAddress = str_replace($matches[0], '', $streetAddress);
         $streetAddress = trim($streetAddress);
     }
     // consider remaining string as street name.
     $parseFields['street_name'] = $streetAddress;
     //run parsed fields through stripSpaces to clean
     foreach ($parseFields as $parseField => $value) {
         $parseFields[$parseField] = CRM_Utils_String::stripSpaces($value);
     }
//.........这里部分代码省略.........
开发者ID:nganivet,项目名称:civicrm-core,代码行数:101,代码来源:Address.php

示例2: processGreetings

 /**
  * Function to process greetings and cache
  *
  */
 static function processGreetings(&$contact)
 {
     // store object values to an array
     $contactDetails = array();
     CRM_Core_DAO::storeValues($contact, $contactDetails);
     $contactDetails = array(array($contact->id => $contactDetails));
     $emailGreetingString = $postalGreetingString = $addresseeString = null;
     $updateQueryString = array();
     require_once 'CRM/Activity/BAO/Activity.php';
     //email greeting
     if ($contact->contact_type == 'Individual' || $contact->contact_type == 'Household') {
         if ($contact->email_greeting_custom != 'null' && $contact->email_greeting_custom) {
             $emailGreetingString = $contact->email_greeting_custom;
         } else {
             if ($contact->email_greeting_id != 'null' && $contact->email_greeting_id) {
                 // the filter value for Individual contact type is set to 1
                 $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'email_greeting');
                 $emailGreeting = CRM_Core_PseudoConstant::greeting($filter);
                 $emailGreetingString = $emailGreeting[$contact->email_greeting_id];
                 $updateQueryString[] = " email_greeting_custom = NULL ";
             } else {
                 if ($contact->email_greeting_custom) {
                     $updateQueryString[] = " email_greeting_display = NULL ";
                 }
             }
         }
         if ($emailGreetingString) {
             CRM_Activity_BAO_Activity::replaceGreetingTokens($emailGreetingString, $contactDetails, $contact->id);
             $emailGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($emailGreetingString));
             $updateQueryString[] = " email_greeting_display = '{$emailGreetingString}'";
         }
         //postal greetings
         if ($contact->postal_greeting_custom != 'null' && $contact->postal_greeting_custom) {
             $postalGreetingString = $contact->postal_greeting_custom;
         } else {
             if ($contact->postal_greeting_id != 'null' && $contact->postal_greeting_id) {
                 $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'postal_greeting');
                 $postalGreeting = CRM_Core_PseudoConstant::greeting($filter);
                 $postalGreetingString = $postalGreeting[$contact->postal_greeting_id];
                 $updateQueryString[] = " postal_greeting_custom = NULL ";
             } elseif ($contact->postal_greeting_custom) {
                 $updateQueryString[] = " postal_greeting_display = NULL ";
             }
         }
         if ($postalGreetingString) {
             CRM_Activity_BAO_Activity::replaceGreetingTokens($postalGreetingString, $contactDetails, $contact->id);
             $postalGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($postalGreetingString));
             $updateQueryString[] = " postal_greeting_display = '{$postalGreetingString}'";
         }
     }
     // addressee
     if ($contact->addressee_custom != 'null' && $contact->addressee_custom) {
         $addresseeString = $contact->addressee_custom;
     } else {
         if ($contact->addressee_id != 'null' && $contact->addressee_id) {
             $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'addressee');
             $addressee = CRM_Core_PseudoConstant::greeting($filter);
             $addresseeString = $addressee[$contact->addressee_id];
             $updateQueryString[] = " addressee_custom = NULL ";
         } else {
             if ($contact->addressee_custom) {
                 $updateQueryString[] = " addressee_display = NULL ";
             }
         }
     }
     if ($addresseeString) {
         CRM_Activity_BAO_Activity::replaceGreetingTokens($addresseeString, $contactDetails, $contact->id);
         $addresseeString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($addresseeString));
         $updateQueryString[] = " addressee_display = '{$addresseeString}'";
     }
     if (!empty($updateQueryString)) {
         $updateQueryString = implode(',', $updateQueryString);
         $queryString = "UPDATE civicrm_contact SET {$updateQueryString} WHERE id = {$contact->id}";
         CRM_Core_DAO::executeQuery($queryString);
     }
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:80,代码来源:Contact.php

示例3: processGreetings

 /**
  * Process greetings and cache.
  *
  * @param object $contact
  *   Contact object after save.
  * @param bool $useDefaults
  *   Use default greeting values.
  */
 public static function processGreetings(&$contact, $useDefaults = FALSE)
 {
     if ($useDefaults) {
         //retrieve default greetings
         $defaultGreetings = CRM_Core_PseudoConstant::greetingDefaults();
         $contactDefaults = $defaultGreetings[$contact->contact_type];
     }
     // note that contact object not always has required greeting related
     // fields that are required to calculate greeting and
     // also other fields used in tokens etc,
     // hence we need to retrieve it again.
     if ($contact->_query !== FALSE) {
         $contact->find(TRUE);
     }
     // store object values to an array
     $contactDetails = array();
     CRM_Core_DAO::storeValues($contact, $contactDetails);
     $contactDetails = array(array($contact->id => $contactDetails));
     $emailGreetingString = $postalGreetingString = $addresseeString = NULL;
     $updateQueryString = array();
     //cache email and postal greeting to greeting display
     if ($contact->email_greeting_custom != 'null' && $contact->email_greeting_custom) {
         $emailGreetingString = $contact->email_greeting_custom;
     } elseif ($contact->email_greeting_id != 'null' && $contact->email_greeting_id) {
         // the filter value for Individual contact type is set to 1
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'email_greeting');
         $emailGreeting = CRM_Core_PseudoConstant::greeting($filter);
         $emailGreetingString = $emailGreeting[$contact->email_greeting_id];
         $updateQueryString[] = " email_greeting_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['email_greeting']);
             $emailGreetingID = key($contactDefaults['email_greeting']);
             $emailGreetingString = $contactDefaults['email_greeting'][$emailGreetingID];
             $updateQueryString[] = " email_greeting_id = {$emailGreetingID} ";
             $updateQueryString[] = " email_greeting_custom = NULL ";
         } elseif ($contact->email_greeting_custom) {
             $updateQueryString[] = " email_greeting_display = NULL ";
         }
     }
     if ($emailGreetingString) {
         CRM_Contact_BAO_Contact_Utils::processGreetingTemplate($emailGreetingString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $emailGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($emailGreetingString));
         $updateQueryString[] = " email_greeting_display = '{$emailGreetingString}'";
     }
     //postal greetings
     if ($contact->postal_greeting_custom != 'null' && $contact->postal_greeting_custom) {
         $postalGreetingString = $contact->postal_greeting_custom;
     } elseif ($contact->postal_greeting_id != 'null' && $contact->postal_greeting_id) {
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'postal_greeting');
         $postalGreeting = CRM_Core_PseudoConstant::greeting($filter);
         $postalGreetingString = $postalGreeting[$contact->postal_greeting_id];
         $updateQueryString[] = " postal_greeting_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['postal_greeting']);
             $postalGreetingID = key($contactDefaults['postal_greeting']);
             $postalGreetingString = $contactDefaults['postal_greeting'][$postalGreetingID];
             $updateQueryString[] = " postal_greeting_id = {$postalGreetingID} ";
             $updateQueryString[] = " postal_greeting_custom = NULL ";
         } elseif ($contact->postal_greeting_custom) {
             $updateQueryString[] = " postal_greeting_display = NULL ";
         }
     }
     if ($postalGreetingString) {
         CRM_Contact_BAO_Contact_Utils::processGreetingTemplate($postalGreetingString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $postalGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($postalGreetingString));
         $updateQueryString[] = " postal_greeting_display = '{$postalGreetingString}'";
     }
     // addressee
     if ($contact->addressee_custom != 'null' && $contact->addressee_custom) {
         $addresseeString = $contact->addressee_custom;
     } elseif ($contact->addressee_id != 'null' && $contact->addressee_id) {
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'addressee');
         $addressee = CRM_Core_PseudoConstant::greeting($filter);
         $addresseeString = $addressee[$contact->addressee_id];
         $updateQueryString[] = " addressee_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['addressee']);
             $addresseeID = key($contactDefaults['addressee']);
             $addresseeString = $contactDefaults['addressee'][$addresseeID];
             $updateQueryString[] = " addressee_id = {$addresseeID} ";
             $updateQueryString[] = " addressee_custom = NULL ";
         } elseif ($contact->addressee_custom) {
             $updateQueryString[] = " addressee_display = NULL ";
         }
     }
     if ($addresseeString) {
         CRM_Contact_BAO_Contact_Utils::processGreetingTemplate($addresseeString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $addresseeString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($addresseeString));
         $updateQueryString[] = " addressee_display = '{$addresseeString}'";
//.........这里部分代码省略.........
开发者ID:JSProffitt,项目名称:civicrm-website-org,代码行数:101,代码来源:Contact.php

示例4: processGreetings

 /**
  * Function to process greetings and cache
  *
  */
 static function processGreetings(&$contact, $useDefaults = FALSE)
 {
     if ($useDefaults) {
         //retrieve default greetings
         $defaultGreetings = CRM_Core_PseudoConstant::greetingDefaults();
         $contactDefaults = $defaultGreetings[$contact->contact_type];
     }
     // store object values to an array
     $contactDetails = array();
     CRM_Core_DAO::storeValues($contact, $contactDetails);
     $contactDetails = array(array($contact->id => $contactDetails));
     $emailGreetingString = $postalGreetingString = $addresseeString = NULL;
     $updateQueryString = array();
     //cache email and postal greeting to greeting display
     if ($contact->email_greeting_custom != 'null' && $contact->email_greeting_custom) {
         $emailGreetingString = $contact->email_greeting_custom;
     } elseif ($contact->email_greeting_id != 'null' && $contact->email_greeting_id) {
         // the filter value for Individual contact type is set to 1
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'email_greeting');
         $emailGreeting = CRM_Core_PseudoConstant::greeting($filter);
         $emailGreetingString = $emailGreeting[$contact->email_greeting_id];
         $updateQueryString[] = " email_greeting_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['email_greeting']);
             $emailGreetingID = key($contactDefaults['email_greeting']);
             $emailGreetingString = $contactDefaults['email_greeting'][$emailGreetingID];
             $updateQueryString[] = " email_greeting_id = {$emailGreetingID} ";
             $updateQueryString[] = " email_greeting_custom = NULL ";
         } elseif ($contact->email_greeting_custom) {
             $updateQueryString[] = " email_greeting_display = NULL ";
         }
     }
     if ($emailGreetingString) {
         CRM_Utils_Token::replaceGreetingTokens($emailGreetingString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $emailGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($emailGreetingString));
         $updateQueryString[] = " email_greeting_display = '{$emailGreetingString}'";
     }
     //postal greetings
     if ($contact->postal_greeting_custom != 'null' && $contact->postal_greeting_custom) {
         $postalGreetingString = $contact->postal_greeting_custom;
     } elseif ($contact->postal_greeting_id != 'null' && $contact->postal_greeting_id) {
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'postal_greeting');
         $postalGreeting = CRM_Core_PseudoConstant::greeting($filter);
         $postalGreetingString = $postalGreeting[$contact->postal_greeting_id];
         $updateQueryString[] = " postal_greeting_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['postal_greeting']);
             $postalGreetingID = key($contactDefaults['postal_greeting']);
             $postalGreetingString = $contactDefaults['postal_greeting'][$postalGreetingID];
             $updateQueryString[] = " postal_greeting_id = {$postalGreetingID} ";
             $updateQueryString[] = " postal_greeting_custom = NULL ";
         } elseif ($contact->postal_greeting_custom) {
             $updateQueryString[] = " postal_greeting_display = NULL ";
         }
     }
     if ($postalGreetingString) {
         CRM_Utils_Token::replaceGreetingTokens($postalGreetingString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $postalGreetingString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($postalGreetingString));
         $updateQueryString[] = " postal_greeting_display = '{$postalGreetingString}'";
     }
     // addressee
     if ($contact->addressee_custom != 'null' && $contact->addressee_custom) {
         $addresseeString = $contact->addressee_custom;
     } elseif ($contact->addressee_id != 'null' && $contact->addressee_id) {
         $filter = array('contact_type' => $contact->contact_type, 'greeting_type' => 'addressee');
         $addressee = CRM_Core_PseudoConstant::greeting($filter);
         $addresseeString = $addressee[$contact->addressee_id];
         $updateQueryString[] = " addressee_custom = NULL ";
     } else {
         if ($useDefaults) {
             reset($contactDefaults['addressee']);
             $addresseeID = key($contactDefaults['addressee']);
             $addresseeString = $contactDefaults['addressee'][$addresseeID];
             $updateQueryString[] = " addressee_id = {$addresseeID} ";
             $updateQueryString[] = " addressee_custom = NULL ";
         } elseif ($contact->addressee_custom) {
             $updateQueryString[] = " addressee_display = NULL ";
         }
     }
     if ($addresseeString) {
         CRM_Utils_Token::replaceGreetingTokens($addresseeString, $contactDetails, $contact->id, 'CRM_Contact_BAO_Contact');
         $addresseeString = CRM_Core_DAO::escapeString(CRM_Utils_String::stripSpaces($addresseeString));
         $updateQueryString[] = " addressee_display = '{$addresseeString}'";
     }
     if (!empty($updateQueryString)) {
         $updateQueryString = implode(',', $updateQueryString);
         $queryString = "UPDATE civicrm_contact SET {$updateQueryString} WHERE id = {$contact->id}";
         CRM_Core_DAO::executeQuery($queryString);
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:96,代码来源:Contact.php


注:本文中的CRM_Utils_String::stripSpaces方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。