forked from Wavyzz/dolibarr
NEW add option keepspace into dol_string_nospecialchar()
This commit is contained in:
@@ -1997,7 +1997,7 @@ class BonPrelevement extends CommonObject
|
|||||||
$XML_DEBITOR .= ' </DbtrAcct>'.$CrLf;
|
$XML_DEBITOR .= ' </DbtrAcct>'.$CrLf;
|
||||||
$XML_DEBITOR .= ' <RmtInf>'.$CrLf;
|
$XML_DEBITOR .= ' <RmtInf>'.$CrLf;
|
||||||
// A string with some information on payment - 140 max
|
// A string with some information on payment - 140 max
|
||||||
$XML_DEBITOR .= ' <Ustrd>'.getDolGlobalString('PRELEVEMENT_USTRD', dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($row_ref.($row_comment ? ' - '.$row_comment : '')), ''), 135, 'right', 'UTF-8', 1))).'</Ustrd>'.$CrLf; // Free unstuctured data - 140 max
|
$XML_DEBITOR .= ' <Ustrd>'.getDolGlobalString('PRELEVEMENT_USTRD', dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($row_ref.($row_comment ? ' - '.$row_comment : '')), '', '', '', 1), 135, 'right', 'UTF-8', 1))).'</Ustrd>'.$CrLf; // Free unstuctured data - 140 max
|
||||||
$XML_DEBITOR .= ' </RmtInf>'.$CrLf;
|
$XML_DEBITOR .= ' </RmtInf>'.$CrLf;
|
||||||
$XML_DEBITOR .= ' </DrctDbtTxInf>'.$CrLf;
|
$XML_DEBITOR .= ' </DrctDbtTxInf>'.$CrLf;
|
||||||
return $XML_DEBITOR;
|
return $XML_DEBITOR;
|
||||||
@@ -2066,7 +2066,7 @@ class BonPrelevement extends CommonObject
|
|||||||
$XML_CREDITOR .= ' </CdtrAcct>'.$CrLf;
|
$XML_CREDITOR .= ' </CdtrAcct>'.$CrLf;
|
||||||
$XML_CREDITOR .= ' <RmtInf>'.$CrLf;
|
$XML_CREDITOR .= ' <RmtInf>'.$CrLf;
|
||||||
// A string with some information on payment - 140 max
|
// A string with some information on payment - 140 max
|
||||||
$XML_CREDITOR .= ' <Ustrd>'.getDolGlobalString('CREDITTRANSFER_USTRD', dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($row_ref.($row_comment ? ' - '.$row_comment : '')), '')), 135, 'right', 'UTF-8', 1)).'</Ustrd>'.$CrLf; // Free unstructured data - 140 max
|
$XML_CREDITOR .= ' <Ustrd>'.getDolGlobalString('CREDITTRANSFER_USTRD', dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($row_ref.($row_comment ? ' - '.$row_comment : '')), '', '', '', 1)), 135, 'right', 'UTF-8', 1)).'</Ustrd>'.$CrLf; // Free unstructured data - 140 max
|
||||||
$XML_CREDITOR .= ' </RmtInf>'.$CrLf;
|
$XML_CREDITOR .= ' </RmtInf>'.$CrLf;
|
||||||
$XML_CREDITOR .= ' </CdtTrfTxInf>'.$CrLf;
|
$XML_CREDITOR .= ' </CdtTrfTxInf>'.$CrLf;
|
||||||
return $XML_CREDITOR;
|
return $XML_CREDITOR;
|
||||||
|
|||||||
@@ -1447,13 +1447,17 @@ function dol_string_unaccent($str)
|
|||||||
* @param string $newstr String to replace forbidden chars with
|
* @param string $newstr String to replace forbidden chars with
|
||||||
* @param array|string $badcharstoreplace Array of forbidden characters to replace. Use '' to keep default list.
|
* @param array|string $badcharstoreplace Array of forbidden characters to replace. Use '' to keep default list.
|
||||||
* @param array|string $badcharstoremove Array of forbidden characters to remove. Use '' to keep default list.
|
* @param array|string $badcharstoremove Array of forbidden characters to remove. Use '' to keep default list.
|
||||||
|
* @param int $keepspaces 1=Do not treat space as a special char to replace or remove
|
||||||
* @return string Cleaned string
|
* @return string Cleaned string
|
||||||
*
|
*
|
||||||
* @see dol_sanitizeFilename(), dol_string_unaccent(), dol_string_nounprintableascii()
|
* @see dol_sanitizeFilename(), dol_string_unaccent(), dol_string_nounprintableascii()
|
||||||
*/
|
*/
|
||||||
function dol_string_nospecial($str, $newstr = '_', $badcharstoreplace = '', $badcharstoremove = '')
|
function dol_string_nospecial($str, $newstr = '_', $badcharstoreplace = '', $badcharstoremove = '', $keepspaces = 0)
|
||||||
{
|
{
|
||||||
$forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ",", ";", "=", '°', '$', ';'); // more complete than dol_sanitizeFileName
|
$forbidden_chars_to_replace = array("'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ",", ";", "=", '°', '$', ';'); // more complete than dol_sanitizeFileName
|
||||||
|
if (empty($keepspaces)) {
|
||||||
|
$forbidden_chars_to_replace[] = " ";
|
||||||
|
}
|
||||||
$forbidden_chars_to_remove = array();
|
$forbidden_chars_to_remove = array();
|
||||||
//$forbidden_chars_to_remove=array("(",")");
|
//$forbidden_chars_to_remove=array("(",")");
|
||||||
|
|
||||||
|
|||||||
@@ -673,6 +673,24 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testDolStringNoSpecial
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function testDolStringNoSpecial()
|
||||||
|
{
|
||||||
|
$text="A string with space and special char like ' or ° and more...\n";
|
||||||
|
$after=dol_string_nospecial($text, '_', '', '', 0);
|
||||||
|
$this->assertEquals("A_string_with_space_and_special_char_like___or___and_more...\n", $after, "testDolStringNoSpecial 1");
|
||||||
|
|
||||||
|
$text="A string with space and special char like ' or ° and more...\n";
|
||||||
|
$after=dol_string_nospecial($text, '_', '', '', 1);
|
||||||
|
$this->assertEquals("A string with space and special char like _ or _ and more...\n", $after, "testDolStringNoSpecial 2");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testDolStringNohtmltag
|
* testDolStringNohtmltag
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user