本文整理汇总了PHP中Contao\StringUtil::splitCsv方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::splitCsv方法的具体用法?PHP StringUtil::splitCsv怎么用?PHP StringUtil::splitCsv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contao\StringUtil
的用法示例。
在下文中一共展示了StringUtil::splitCsv方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processFormData
/**
* Process form data, store it in the session and redirect to the jumpTo page
*
* @param array $arrSubmitted
* @param array $arrLabels
* @param array $arrFields
*/
protected function processFormData($arrSubmitted, $arrLabels, $arrFields)
{
// HOOK: prepare form data callback
if (isset($GLOBALS['TL_HOOKS']['prepareFormData']) && is_array($GLOBALS['TL_HOOKS']['prepareFormData'])) {
foreach ($GLOBALS['TL_HOOKS']['prepareFormData'] as $callback) {
$this->import($callback[0]);
$this->{$callback[0]}->{$callback[1]}($arrSubmitted, $arrLabels, $arrFields, $this);
}
}
// Send form data via e-mail
if ($this->sendViaEmail) {
$keys = array();
$values = array();
$fields = array();
$message = '';
foreach ($arrSubmitted as $k => $v) {
if ($k == 'cc') {
continue;
}
$v = \StringUtil::deserialize($v);
// Skip empty fields
if ($this->skipEmpty && !is_array($v) && !strlen($v)) {
continue;
}
// Add field to message
$message .= (isset($arrLabels[$k]) ? $arrLabels[$k] : ucfirst($k)) . ': ' . (is_array($v) ? implode(', ', $v) : $v) . "\n";
// Prepare XML file
if ($this->format == 'xml') {
$fields[] = array('name' => $k, 'values' => is_array($v) ? $v : array($v));
}
// Prepare CSV file
if ($this->format == 'csv') {
$keys[] = $k;
$values[] = is_array($v) ? implode(',', $v) : $v;
}
}
$recipients = \StringUtil::splitCsv($this->recipient);
// Format recipients
foreach ($recipients as $k => $v) {
$recipients[$k] = str_replace(array('[', ']', '"'), array('<', '>', ''), $v);
}
$email = new \Email();
// Get subject and message
if ($this->format == 'email') {
$message = $arrSubmitted['message'];
$email->subject = $arrSubmitted['subject'];
}
// Set the admin e-mail as "from" address
$email->from = $GLOBALS['TL_ADMIN_EMAIL'];
$email->fromName = $GLOBALS['TL_ADMIN_NAME'];
// Get the "reply to" address
if (strlen(\Input::post('email', true))) {
$replyTo = \Input::post('email', true);
// Add name
if (strlen(\Input::post('name'))) {
$replyTo = '"' . \Input::post('name') . '" <' . $replyTo . '>';
}
$email->replyTo($replyTo);
}
// Fallback to default subject
if (!strlen($email->subject)) {
$email->subject = $this->replaceInsertTags($this->subject, false);
}
// Send copy to sender
if (strlen($arrSubmitted['cc'])) {
$email->sendCc(\Input::post('email', true));
unset($_SESSION['FORM_DATA']['cc']);
}
// Attach XML file
if ($this->format == 'xml') {
/** @var FrontendTemplate|object $objTemplate */
$objTemplate = new \FrontendTemplate('form_xml');
$objTemplate->fields = $fields;
$objTemplate->charset = \Config::get('characterSet');
$email->attachFileFromString($objTemplate->parse(), 'form.xml', 'application/xml');
}
// Attach CSV file
if ($this->format == 'csv') {
$email->attachFileFromString(\StringUtil::decodeEntities('"' . implode('";"', $keys) . '"' . "\n" . '"' . implode('";"', $values) . '"'), 'form.csv', 'text/comma-separated-values');
}
$uploaded = '';
// Attach uploaded files
if (!empty($_SESSION['FILES'])) {
foreach ($_SESSION['FILES'] as $file) {
// Add a link to the uploaded file
if ($file['uploaded']) {
$uploaded .= "\n" . \Environment::get('base') . str_replace(TL_ROOT . '/', '', dirname($file['tmp_name'])) . '/' . rawurlencode($file['name']);
continue;
}
$email->attachFileFromString(file_get_contents($file['tmp_name']), $file['name'], $file['type']);
}
}
$uploaded = strlen(trim($uploaded)) ? "\n\n---\n" . $uploaded : '';
//.........这里部分代码省略.........
示例2: splitCsv
/**
* Split a string of comma separated values.
*
* @param string $strString The string to split.
*
* @param string $strDelimiter An optional delimiter.
*
* @return array The string chunks
*/
public static function splitCsv($strString, $strDelimiter = ',')
{
if (self::isStringUtilAvailable()) {
return StringUtil::splitCsv($strString, $strDelimiter);
}
return \Contao\String::splitCsv($strString, $strDelimiter);
}