Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

str_replace_formatted_placeholder()

Description

Returns a string with all occurrences of the $mixedplaceholder in $subject replaced with the $mixedreplace.
If $mixedplaceholder is a string but $mixedreplace is an array, the $mixedreplace is imploded to a string using $separator.
The replace values are formatted according to the formatting of the placeholders.
The placeholders may be written in UPPERCASE, lowercase or Uppercasefirst.
Each placeholder will be replaced by the replace value,
written with the same case as the placeholder.
It's possible to also include "?" as a placeholder for legacy reasons.

Example #1:
str_replace_formatted_placeholder("%extension", $resource["file_extension"], $lang["originalfileoftype"], true)
will search for the three words "%EXTENSION", "%extension" and "%Extension" and also the char "?"
in the string $lang["originalfileoftype"]. If the found placeholder is %extension
it will be replaced by the value of $resource["file_extension"],
written in lowercase. If the found placeholder instead would have been "?" the value
would have been written in UPPERCASE.

Example #2:
str_replace_formatted_placeholder("%resourcetypes%", $searched_resource_types_names_array,
$lang["resourcetypes-collections"], false, $lang["resourcetypes_separator"])
will search for the three words "%RESOURCETYPES%", "%resourcetypes%" and "%Resourcetypes%"
in the string $lang["resourcetypes-collections"]. If the found placeholder is %resourcetypes%
all elements in $searched_resource_types_names_array will be written in lowercase and separated by
$lang["resourcetypes_separator"] before the resulting string will replace the placeholder.

Parameters

ColumnTypeDefaultDescription
$mixedplaceholder mixed
$mixedreplace mixed
$subject mixed
$question_mark mixed false
$separator string "
"

Return

string

Location

include/language_functions.php lines 261 to 307

Definition

 
function str_replace_formatted_placeholder($mixedplaceholder$mixedreplace$subject$question_mark false$separator ", ")
    {
    
# Creates a multi-dimensional array of the placeholders written in different case styles.
    
$array_placeholder = array();
    if (
is_array($mixedplaceholder)) {$placeholder $mixedplaceholder;}
    else {
$placeholder = array($mixedplaceholder);}
    for (
$n 0;$n<count($placeholder);$n++)
        {
        
$array_placeholder[$n] = array(strtoupper((string)$placeholder[$n]), strtolower((string)$placeholder[$n]), ucfirstletter((string)$placeholder[$n]));
        }

    
# Creates a multi-dimensional array of the replace values written in different case styles.
    
if (is_array($mixedreplace)) {$replace $mixedreplace;}
    else {
$replace = array($mixedreplace);}
    for (
$n 0;$n<count($replace);$n++)
        {
        
$array_replace[$n] = array(strtoupper((string)$replace[$n]), strtolower((string)$replace[$n]), ucfirst(strtolower((string)$replace[$n])));
        }

    
# Adds "?" to the arrays if required.
    
if ($question_mark)
        {
        
$array_placeholder[] = "?";
        
$array_replace[] = strtoupper((string)$replace[0]);
        }

    
# Replaces the placeholders with the replace values and returns the new string.
    
$result $subject;
    if (
count($placeholder)==&& count($replace)>1)
        {
        
# The placeholder shall be replaced by an imploded array.
        
$array_replace_strings = array(implode($separatorarray_map(function($column) {return $column[0];}, $array_replace)), implode($separatorarray_map(function($column) {return $column[1];}, $array_replace)), implode($separatorarray_map(function($column) {return $column[2];}, $array_replace)));
        
$result str_replace($array_placeholder[0], $array_replace_strings$result);
        }
    else
        {
        for (
$n=0;$n<count($placeholder);$n++)
            {
            if (!isset(
$array_replace[$n][0])) {break;}
            else
                {
                
$result str_replace($array_placeholder[$n], $array_replace[$n], $result);
                }
            }
        }
    return 
$result;
    }

This article was last updated 14th December 2024 08:05 Europe/London time based on the source file dated 27th November 2024 15:30 Europe/London time.