function featureExtractor($tweet) { $tweet = removeUrlAndUserNames($tweet); $tweet = replaceEmoticons($tweet); $tweet = changeCase($tweet); $tweet = separateWords($tweet); $tweet = stripSpecialChar($tweet); $tweet = removeEmptyWords($tweet); $tweet = removeStopWords($tweet); $tweet = replaceMultiLetterSpelling($tweet); return $tweet; }
<?php include '../../function.php'; $letter = array('a' => 'A', 'b' => 'B', 'c' => array('d' => 'D', 'e' => 'E', 'f' => 'F'), 'g' => 'G'); function changeCase($arr) { // 遍历 foreach ($arr as $key => $value) { // 判断 if (is_array($value)) { // 改变下标为大写 $newarr = array_change_key_case($valueC, ASE_UPPER); return $newarr; } } } p($letter); $re = changeCase($letter); p($re); ?>
function csaToRefbase($sourceText, $importRecordsRadio, $importRecordNumbersArray) { global $alnum, $alpha, $cntrl, $dash, $digit, $graph, $lower, $print, $punct, $space, $upper, $word, $patternModifiers; // defined in 'transtab_unicode_charset.inc.php' and 'transtab_latin1_charset.inc.php' global $errors; global $showSource; // Defines the pattern by which the input text will be split into individual records: $recordDelimiter = "\\s*Record \\d+ of \\d+\\s*"; // PRE-PROCESS SOURCE TEXT: // Split input text into individual records: $recordArray = splitSourceText($sourceText, $recordDelimiter, false); // split input text on the header text preceeding each CSA record (e.g. "\nRecord 4 of 52\n") // Count how many records are available: $recordsCount = count($recordArray); // ---------------------------------------------------------------- // VALIDATE INDIVIDUAL RECORDS: // Note that source data must begin with "\nRecord x of xx\n" and that (opposed to the handling in 'import_csa_modify.php') any text preceeding the source data isn't removed but treated as the first record! // This array lists patterns which match all CSA tags that must occur within a record to be recognized as valid CSA record: // (Array keys must contain the tag name as it should be displayed to the user; as is the case with search & replace actions, // the search patterns MUST include the leading & trailing slashes.) // "tag display name" => "tag search pattern" $requiredTagsArray = array("title" => "/^TI: Title *[\r\n]+ {4,4}/m", "author (or editor)" => "/^(AU: Author|ED: Editor) *[\r\n]+ {4,4}/m", "source" => "/^SO: Source *[\r\n]+ {4,4}/m"); // Validate all records that shall be imported: list($errors, $importRecordNumbersRecognizedFormatArray, $importRecordNumbersNotRecognizedFormatArray) = validateRecords($recordArray, $requiredTagsArray, $importRecordsRadio, $importRecordNumbersArray, $errors); // ---------------------------------------------------------------- // PROCESS SOURCE DATA: $parsedRecordsArray = array(); // initialize array variable which will hold parsed data of all records that shall be imported // LOOP OVER EACH RECORD: for ($i = 0; $i < $recordsCount; $i++) { // if we're NOT supposed to import this record (because it was either not selected by the user -OR- because it did contain an unrecognized data format) if (!in_array($i + 1, $importRecordNumbersRecognizedFormatArray)) { continue; // process next record (if any) } else { $singleRecord = $recordArray[$i]; // if the "AU: Author" field is missing BUT the "ED: Editor" is present (which is allowed for book monographs): // we replace the "ED: Editor" field identifier with "AU: Author" (this will keep any " (ed)" and " (eds)" tags in place which, in turn, will cause the "is Editor" checkbox in 'record.php' to get marked) if (!preg_match("/^AU: Author *[\r\n]+ {4,4}/m", $singleRecord) and preg_match("/^ED: Editor *[\r\n]+ {4,4}/m", $singleRecord) and preg_match("/^(PT: Publication Type\\s+Book Monograph|DT: Document Type\\s+B)/m", $singleRecord)) { $singleRecord = preg_replace("/^ED: Editor(?= *[\r\n]+ {4,4})/m", "AU: Author", $singleRecord); } // split each record into its fields: $fieldArray = preg_split("/[\r\n]+(?=\\w\\w: )/", $singleRecord); // initialize some variables: $fieldParametersArray = array(); // setup an empty array (it will hold all fields that were extracted for a given record) $additionalDocumentTypeInfo = ""; // will be used with the "PT: Publication Type" field $environmentalRegime = ""; // will be used with the "ER: Environmental Regime" field // GENERATE EXTRA FIELDS: // check if the fields "MT: Monograph Title", "JN: Journal Name", "JV: Journal Volume", "JI: Journal Issue" and "JP: Journal Pages" are present, // if not, we attempt to generate them from the "SO: Source" field: $sourceField = preg_replace("/.*SO: Source *[\r\n]+ {4,4}(.+?)(?=([\r\n]+\\w\\w: |\\s*\\z)).*/ms", "\\1", $singleRecord); // first, we need to extract the "SO: Source" field data from the record text $sourceField = preg_replace("/\\s{2,}/", " ", $sourceField); // remove any hard returns and extra spaces within the source field data string // if the current record is of type "Book Monograph" but the field "MT: Monograph Title" is missing: if (preg_match("/^(PT: Publication Type\\s+Book Monograph|DT: Document Type\\s+B)/m", $singleRecord) and !preg_match("/^MT: Monograph Title *[\r\n]+ {4,4}/m", $singleRecord)) { $extractedSourceFieldData = preg_replace("/^([^.[]+).*/", "\\1", $sourceField); // attempt to extract the full monograph title from the source field if (preg_match("/^[{$upper}\\W\\d]+\$/{$patternModifiers}", $extractedSourceFieldData)) { // if all of the words within the monograph title are uppercase, we attempt to convert the string to something more readable: // perform case transformation (e.g. convert "BIOLOGY AND ECOLOGY OF GLACIAL RELICT CRUSTACEA" into "Biology And Ecology Of Glacial Relict Crustacea") $extractedSourceFieldData = changeCase('title', $extractedSourceFieldData); } // function 'changeCase()' is defined in 'include.inc.php' $fieldArray[] = "MT: Monograph Title\r\n " . $extractedSourceFieldData; // add field "MT: Monograph Title" to the array of fields } elseif (!preg_match("/^JN: Journal Name *[\r\n]+ {4,4}/m", $singleRecord)) { if (preg_match("/\\[/", $sourceField)) { // if the source field data contain a square bracket we assume a format like: "Journal of Phycology [J. Phycol.]. Vol. 37, no. s3, pp. 18-18. Jun 2001." $extractedSourceFieldData = preg_replace("/^([^.[]+).*/", "\\1", $sourceField); } else { // source field format might be something like: "Phycologia, vol. 34, no. 2, pp. 135-144, 1995" $extractedSourceFieldData = preg_replace("/^([^.,]+).*/", "\\1", $sourceField); } // attempt to extract the full journal name from the source field if (preg_match("/^[{$upper}\\W\\d]+\$/{$patternModifiers}", $extractedSourceFieldData)) { // if all of the words within the journal name are uppercase, we attempt to convert the string to something more readable: // perform case transformation (e.g. convert "POLAR BIOLOGY" into "Polar Biology") $extractedSourceFieldData = changeCase('title', $extractedSourceFieldData); } $fieldArray[] = "JN: Journal Name\r\n " . $extractedSourceFieldData; // add field "JN: Journal Name" to the array of fields } // if the "JV: Journal Volume" is missing BUT the "SO: Source" field contains a volume specification: if (!preg_match("/^JV: Journal Volume *[\r\n]+ {4,4}/m", $singleRecord) and preg_match("/(?<=\\W)vol[. ]+[\\w\\/-]+/i", $sourceField)) { $extractedSourceFieldData = preg_replace("/.*(?<=\\W)vol[. ]+([\\w\\/-]+).*/i", "\\1", $sourceField); // attempt to extract the journal volume from the source field $fieldArray[] = "JV: Journal Volume\r\n " . $extractedSourceFieldData; // add field "JV: Journal Volume" to the array of fields } // if the "JI: Journal Issue" is missing BUT the "SO: Source" field contains an issue specification: if (!preg_match("/^JI: Journal Issue *[\r\n]+ {4,4}/m", $singleRecord) and preg_match("/(?<=\\W)no[. ]+[\\w\\/-]+/i", $sourceField)) { $extractedSourceFieldData = preg_replace("/.*(?<=\\W)no[. ]+([\\w\\/-]+).*/i", "\\1", $sourceField); // attempt to extract the journal issue from the source field $fieldArray[] = "JI: Journal Issue\r\n " . $extractedSourceFieldData; // add field "JI: Journal Issue" to the array of fields } // if the "JP: Journal Pages" is missing BUT the "SO: Source" field contains a pages specification: if (!preg_match("/^JP: Journal Pages *[\r\n]+ {4,4}/m", $singleRecord) and preg_match("/((?<=\\W)pp?[. ]+[\\w\\/,-]+|[\\d,]+ *pp\\b)/i", $sourceField)) { if (preg_match("/(?<=\\W)pp?[. ]+[\\w\\/,-]+/i", $sourceField)) { // e.g. "pp. 212-217" or "p. 216" etc $extractedSourceFieldData = preg_replace("/.*(?<=\\W)pp?[. ]+([\\w\\/,-]+).*/i", "\\1", $sourceField); } elseif (preg_match("/[\\d,]+ *pp\\b/", $sourceField)) { // e.g. "452 pp" $extractedSourceFieldData = preg_replace("/.*?([\\d,]+ *pp)\\b.*/i", "\\1", $sourceField); } // attempt to extract the journal pages from the source field $extractedSourceFieldData = preg_replace("/,/", "", $extractedSourceFieldData); // remove any thousands separators from journal pages $fieldArray[] = "JP: Journal Pages\r\n " . $extractedSourceFieldData; // add field "JP: Journal Pages" to the array of fields } // Additionally, we extract the abbreviated journal name from the "SO: Source" field (if available): if (preg_match("/\\[/", $sourceField)) { $extractedSourceFieldData = preg_replace("/.*\\[(.+?)\\].*/", "\\1", $sourceField); // attempt to extract the abbreviated journal name from the source field $extractedSourceFieldData = preg_replace("/\\./", "", $extractedSourceFieldData); // remove any dots from the abbreviated journal name if (preg_match("/^[{$upper}\\W\\d]+\$/{$patternModifiers}", $extractedSourceFieldData)) { // if all of the words within the abbreviated journal name are uppercase, we attempt to convert the string to something more readable: // perform case transformation (e.g. convert "BALT SEA ENVIRON PROC" into "Balt Sea Environ Proc") $extractedSourceFieldData = changeCase('title', $extractedSourceFieldData); } $fieldArray[] = "JA: Abbrev Journal Name\r\n " . $extractedSourceFieldData; // add field "JA: Abbrev Journal Name" to the array of fields (note that this field normally does NOT occur within the CSA full record format!) } // (END GENERATE EXTRA FIELDS) // LOOP OVER EACH FIELD: foreach ($fieldArray as $singleField) { $singleField = preg_replace("/^(\\w\\w: [^\r\n]+)[\r\n]+ {4,4}/", "\\1___LabelDataSplitter___", $singleField); // insert a unique text string between the field identifier and the field data $fieldLabelPlusDataArray = preg_split("/___LabelDataSplitter___/", $singleField); // split each field into a 2-element array containing [0] the field identifier and [1] the field data $fieldLabel = $fieldLabelPlusDataArray[0]; $fieldData = $fieldLabelPlusDataArray[1]; $fieldData = preg_replace("/\\s{2,}/", " ", $fieldData); // remove any hard returns and extra spaces within the data string $fieldData = trim($fieldData); // remove any preceeding and trailing whitespace from the field data if (preg_match("/AU: Author/", $fieldLabel)) { $fieldData = preg_replace("/\\*/", "", $fieldData); // remove any asterisk ("*") $fieldData = standardizePersonNames($fieldData, true, " *; *", " *, *", true); // standardize person names } elseif (preg_match("/ED: Editor/", $fieldLabel)) { $fieldData = preg_replace("/ \\(eds?\\)(?= *\$| *;)/", "", $fieldData); // remove " (ed)" and/or " (eds)" $fieldData = standardizePersonNames($fieldData, true, " *; *", " *, *", true); // standardize person names } elseif (preg_match("/TI: Title|AB: Abstract/", $fieldLabel)) { if (preg_match("/TI: Title/", $fieldLabel)) { $fieldData = preg_replace("/--/", "-", $fieldData); // remove en-dash markup $fieldData = preg_replace("/ *\\. *\$/", "", $fieldData); // remove any dot from end of title } if (preg_match("/ su(b|per)\\(.+?\\)/", $fieldData)) { $fieldData = preg_replace("/ (su(?:b|per))\\((.+?)\\)/", "[\\1:\\2]", $fieldData); } // transform " sub(...)" & " super(...)" markup into "[sub:...]" & "[super:...]" markup if (preg_match("/(?<= )mu /", $fieldData)) { $fieldData = preg_replace("/(?<= )mu /", "[mu]", $fieldData); } // transform "mu " markup into "[mu]" markup } // BUILD FIELD PARAMETERS: // build an array of key/value pairs: // "AU: Author": if (preg_match("/AU: Author/", $fieldLabel)) { $fieldParametersArray['author'] = $fieldData; } elseif (preg_match("/TI: Title/", $fieldLabel)) { $fieldParametersArray['title'] = $fieldData; } elseif (preg_match("/PT: Publication Type/", $fieldLabel)) { if (preg_match("/[;:,.]/", $fieldData)) { $correctDocumentType = preg_replace("/(.+?)\\s*[;:,.]\\s*.*/", "\\1", $fieldData); // extract everything before this delimiter $additionalDocumentTypeInfo = preg_replace("/.*?\\s*[;:,.]\\s*(.+)/", "\\1", $fieldData); // extract everything after this delimiter $additionalDocumentTypeInfo = $additionalDocumentTypeInfo; // this info will be appended to any notes field data (see below) } else { // we take the "PT: Publication Type" field contents as they are $correctDocumentType = $fieldData; } // Note that for books the "PT: Publication Type" field will always start with "Book Monograph", no matter whether the referenced // publication is a whole book or just a book chapter within that book! This is a design flaw within the CSA full record format. // So we can only apply some "good guessing" whether the current record actually references a complete book or just a book chapter: if (preg_match("/^(PT: Publication Type\\s+Book Monograph|DT: Document Type\\s+B)/m", $singleRecord)) { // and if the source field contains some page specification like "213 pp." (AND NOT something like "pp. 76-82" or "p. 216")... if (preg_match("/[\\d,]+ *pp\\b/i", $sourceField) and !preg_match("/(?<=\\W)pp?[. ]+[\\w\\/,-]+/i", $sourceField)) { $correctDocumentType = "Book Whole"; } else { $correctDocumentType = "Book Chapter"; } // ...otherwise we assume its a book chapter (which may NOT always be correct!) } $fieldParametersArray['type'] = $correctDocumentType; } elseif (preg_match("/PY: Publication Year/", $fieldLabel)) { $fieldParametersArray['year'] = $fieldData; } elseif (preg_match("/JN: Journal Name/", $fieldLabel)) { // if the current record is of type "Book Monograph" AND the field "JN: Journal Name" was given within the *original* record data (i.e., before adding stuff to it): if (preg_match("/^(PT: Publication Type\\s+Book Monograph|DT: Document Type\\s+B)/m", $singleRecord) and preg_match("/^JN: Journal Name *[\r\n]+ {4,4}/m", $singleRecord)) { // for book monographs the publication title is given in "MT: Monograph Title"; if a "JN: Journal Name" was originally provided as well, we assume, it's the series title: $fieldParametersArray['series_title'] = $fieldData; } else { $fieldParametersArray['publication'] = $fieldData; } } elseif (preg_match("/JA: Abbrev Journal Name/", $fieldLabel)) { if (preg_match("/^(PT: Publication Type\\s+Book Monograph|DT: Document Type\\s+B)/m", $singleRecord)) { // if the current record is of type "Book Monograph" // for book monographs the publication title is given in "MT: Monograph Title"; if a "JA: Abbrev Journal Name" is provided as well, we assume, it's the abbreviated series title: $fieldParametersArray['abbrev_series_title'] = $fieldData; } else { $fieldParametersArray['abbrev_journal'] = $fieldData; } } elseif (preg_match("/MT: Monograph Title/", $fieldLabel)) { // if the source field contains some page specification like "213 pp." (AND NOT something like "pp. 76-82" or "p. 216")... if (preg_match("/[\\d,]+ *pp\\b/i", $sourceField) and !preg_match("/(?<=\\W)pp?[. ]+[\\w\\/,-]+/i", $sourceField)) { // ...we assume its a whole book (see above comment), in which case we assign the monograph title to the series title field: $fieldParametersArray['series_title'] = $fieldData; } else { $fieldParametersArray['publication'] = $fieldData; } } elseif (preg_match("/JV: Journal Volume/", $fieldLabel)) { if (preg_match("/^(PT: Publication Type\\s+Book Monograph|DT: Document Type\\s+B)/m", $singleRecord)) { // if the current record is of type "Book Monograph" // for book monographs, if there's a volume given, we assume, it's the series volume: $fieldParametersArray['series_volume'] = $fieldData; } else { $fieldParametersArray['volume'] = $fieldData; } } elseif (preg_match("/JI: Journal Issue/", $fieldLabel)) { if (preg_match("/^(PT: Publication Type\\s+Book Monograph|DT: Document Type\\s+B)/m", $singleRecord)) { // if the current record is of type "Book Monograph" // for book monographs, if there's an issue given, we assume, it's the series issue: $fieldParametersArray['series_issue'] = $fieldData; } else { $fieldParametersArray['issue'] = $fieldData; } } elseif (preg_match("/JP: Journal Pages/", $fieldLabel)) { $fieldParametersArray['pages'] = $fieldData; } elseif (preg_match("/AF: (Author )?Affilia?tion/", $fieldLabel)) { $fieldParametersArray['address'] = $fieldData; } elseif (preg_match("/CA: Corporate Author/", $fieldLabel)) { $fieldParametersArray['corporate_author'] = $fieldData; } elseif (preg_match("/DE: Descriptors/", $fieldLabel)) { // currently, the fields "KW: Keywords" and "ID: Identifiers" are ignored! $fieldParametersArray['keywords'] = $fieldData; } elseif (preg_match("/AB: Abstract/", $fieldLabel)) { $fieldParametersArray['abstract'] = $fieldData; } elseif (preg_match("/PB: Publisher/", $fieldLabel)) { if (preg_match("/^[{$upper}\\W\\d]+\$/{$patternModifiers}", $fieldData)) { // if all of the words within the publisher name are uppercase, we attempt to convert the string to something more readable: // perform case transformation (e.g. convert "ELSEVIER SCIENCE B.V." into "Elsevier Science B.V.") $fieldData = changeCase('title', $fieldData); } $fieldParametersArray['publisher'] = $fieldData; } elseif (preg_match("/ED: Editor/", $fieldLabel)) { $fieldParametersArray['editor'] = $fieldData; } elseif (preg_match("/LA: Language/", $fieldLabel)) { $fieldParametersArray['language'] = $fieldData; } elseif (preg_match("/SL: Summary Language/", $fieldLabel)) { $fieldParametersArray['summary_language'] = $fieldData; } elseif (preg_match("/OT: Original Title/", $fieldLabel)) { $fieldParametersArray['orig_title'] = $fieldData; } elseif (preg_match("/IS: ISSN/", $fieldLabel)) { $fieldParametersArray['issn'] = $fieldData; } elseif (preg_match("/IB: ISBN/", $fieldLabel)) { $fieldParametersArray['isbn'] = $fieldData; } elseif (preg_match("/ER: Environmental Regime/", $fieldLabel)) { $environmentalRegime = $fieldData; } elseif (preg_match("/CF: Conference/", $fieldLabel)) { $fieldParametersArray['conference'] = $fieldData; } elseif (preg_match("/NT: Notes/", $fieldLabel)) { $fieldParametersArray['notes'] = $fieldData; } elseif (preg_match("/DO: DOI/", $fieldLabel)) { $fieldParametersArray['doi'] = $fieldData; } } // (END LOOP OVER EACH FIELD) if (!empty($showSource)) { // if we're supposed to display the original source data // append original source field data (they will be presented within the header message of 'record.php' for easy comparison with the extracted data): $fieldParametersArray['source'] = $sourceField; } // we'll hack the "notes" element in order to append additional info: // (this cannot be done earlier above since we don't know about the presence & order of fields within the source text!) if (!empty($additionalDocumentTypeInfo)) { if (isset($fieldParametersArray['notes'])) { // and if the notes element is present $fieldParametersArray['notes'] = $fieldParametersArray['notes'] . "; " . $additionalDocumentTypeInfo; } else { // the notes parameter wasn't specified yet $fieldParametersArray['notes'] = $additionalDocumentTypeInfo; } // add notes element with additional info from "PT: Publication Type" field } if (!empty($environmentalRegime)) { if (isset($fieldParametersArray['notes'])) { // and if the notes element is present $fieldParametersArray['notes'] = $fieldParametersArray['notes'] . "; " . $environmentalRegime; } else { // the notes parameter wasn't specified yet $fieldParametersArray['notes'] = $environmentalRegime; } // add notes element with "ER: Environmental Regime" field data } // Append the array of extracted field data to the main data array which holds all records to import: $parsedRecordsArray[] = $fieldParametersArray; } } // (END LOOP OVER EACH RECORD) // ---------------------------------------------------------------- // BUILD REFBASE IMPORT ARRAY: $importDataArray = buildImportArray("refbase", "1.0", "http://refbase.net/import/csa/", "Matthias Steffens", "*****@*****.**", array('prefix_call_number' => "true"), $parsedRecordsArray); // 'records' - array of record(s) (with each record being a sub-array of fields) return array($importDataArray, $recordsCount, $importRecordNumbersRecognizedFormatArray, $importRecordNumbersNotRecognizedFormatArray, $errors); }
function handleFileUploads($uploadFile, $formVars) { global $filesBaseDir; // these variables are defined in 'ini.inc.php' global $moveFilesIntoSubDirectories; global $dirNamingScheme; global $renameUploadedFiles; global $fileNamingScheme; global $handleNonASCIIChars; global $allowedFileNameCharacters; global $allowedDirNameCharacters; global $changeCaseInFileNames; global $changeCaseInDirNames; $tmpFilePath = $uploadFile["tmp_name"]; // Generate file name: if ($renameUploadedFiles == "yes") { if (preg_match("/.+\\.[^.]+\$/i", $uploadFile["name"])) { // preserve any existing file name extension $fileNameExtension = preg_replace("/.+(\\.[^.]+)\$/i", "\\1", $uploadFile["name"]); } else { $fileNameExtension = ""; } // auto-generate a file name according to the naming scheme given in '$fileNamingScheme': $newFileName = parsePlaceholderString($formVars, $fileNamingScheme, "<:serial:>"); // function 'parsePlaceholderString()' is defined in 'include.inc.php' // handle non-ASCII and unwanted characters: $newFileName = handleNonASCIIAndUnwantedCharacters($newFileName, $allowedFileNameCharacters, $handleNonASCIIChars); // function 'handleNonASCIIAndUnwantedCharacters()' is defined in 'include.inc.php' // add original file name extension: $newFileName .= $fileNameExtension; } else { // take the file name as given by the user: $newFileName = $uploadFile["name"]; } // Generate directory structure: if ($moveFilesIntoSubDirectories != "never") { // remove any slashes (i.e., directory delimiter(s)) from the beginning or end of '$dirNamingScheme': $dirNamingScheme = trimTextPattern($dirNamingScheme, "[\\/\\\\]+", true, true); // function 'trimTextPattern()' is defined in 'include.inc.php' $dirNamingSchemePartsArray = preg_split("#[/\\\\]+#", $dirNamingScheme); // split on slashes to separate between multiple sub-directories $subDirNamesArray = array(); // initialize array variable which will hold the generated sub-directory names // auto-generate a directory name according to the naming scheme given in '$dirNamingScheme' // and handle non-ASCII chars plus unwanted characters: foreach ($dirNamingSchemePartsArray as $dirNamingSchemePart) { // parse given placeholder string: $subDirName = parsePlaceholderString($formVars, $dirNamingSchemePart, ""); // function 'parsePlaceholderString()' is defined in 'include.inc.php' // handle non-ASCII and unwanted characters: $subDirName = handleNonASCIIAndUnwantedCharacters($subDirName, $allowedDirNameCharacters, $handleNonASCIIChars); // function 'handleNonASCIIAndUnwantedCharacters()' is defined in 'include.inc.php' if (!empty($subDirName)) { $subDirNamesArray[] = $subDirName; } } if (!empty($subDirNamesArray)) { $subDirName = implode("/", $subDirNamesArray) . "/"; } else { $subDirName = ""; } } else { $subDirName = ""; } // Perform any case transformations: // change case of file name: if (preg_match("/^(lower|upper)\$/i", $changeCaseInFileNames)) { $newFileName = changeCase($changeCaseInFileNames, $newFileName); } // function 'changeCase()' is defined in 'include.inc.php' // change case of DIR name: if (preg_match("/^(lower|upper)\$/i", $changeCaseInDirNames) && !empty($subDirName)) { $subDirName = changeCase($changeCaseInDirNames, $subDirName); } // Generate full destination path: // - if '$moveFilesIntoSubDirectories = "existing"' and there's an existing sub-directory (within the default files directory '$filesBaseDir') // whose name equals '$subDirName' we'll copy the new file into that sub-directory // - if '$moveFilesIntoSubDirectories = "always"' and '$subDirName' isn't empty, we'll generate an appropriately named sub-directory if it // doesn't exist yet // - otherwise we just copy the file to the root-level of '$filesBaseDir': if (!empty($subDirName) && ($moveFilesIntoSubDirectories == "existing" and is_dir($filesBaseDir . $subDirName) or $moveFilesIntoSubDirectories == "always")) { $destFilePath = $filesBaseDir . $subDirName . $newFileName; // new file will be copied into sub-directory within '$filesBaseDir'... // copy the new subdir name & file name to the 'file' field variable: // Note: if a user uploads a file and there was already a file specified within the 'file' field, the old file will NOT get removed // from the files directory! Automatic file removal is omitted on purpose since it's way more difficult to recover an // inadvertently deleted file than to delete it manually. However, future versions should introduce a smarter way of handling // orphaned files... $fileName = $subDirName . $newFileName; if ($moveFilesIntoSubDirectories == "always" and !is_dir($filesBaseDir . $subDirName)) { // make sure the directory we're moving the file to exists before proceeding: recursiveMkdir($filesBaseDir . $subDirName); } } else { $destFilePath = $filesBaseDir . $newFileName; // new file will be copied to root-level of '$filesBaseDir'... $fileName = $newFileName; // copy the new file name to the 'file' field variable (see note above!) } // Copy uploaded file from temporary location to the default file directory specified in '$filesBaseDir': // (for more on PHP file uploads see <http://www.php.net/manual/en/features.file-upload.php>) move_uploaded_file($tmpFilePath, $destFilePath); return $fileName; }
<?php $fh = fopen($argv[1], "r"); while (!feof($fh)) { $val = fgets($fh); if ($val != "") { $allChar = str_split(trim($val)); $upperCase = true; foreach ($allChar as $char) { if (ctype_alpha($char)) { echo changeCase($char, $upperCase); $upperCase = !$upperCase; } else { echo $char; } } echo PHP_EOL; } } fclose($fh); function changeCase($char, $boolean) { return $boolean ? strtoupper($char) : strtolower($char); }