Skip to content

Files

Latest commit

2e8b7ff · Aug 27, 2018

History

History
executable file
·
103 lines (76 loc) · 2.65 KB

Strings.md

File metadata and controls

executable file
·
103 lines (76 loc) · 2.65 KB

NFePHP\Common\Strings::class

Auxiliar class for strings treatment

Methods

replaceSpecialsChars($string)

Replace all specials characters from string and retuns only 128 basic characters. [a-z] [A-Z] [0-9] @ space , - . ; : $ %

NOTE: only UTF-8

  • @param string $string
  • @return string
    $str = "Á é ç ";
    $ret = Strings::replaceSpecialsChars($str);
    echo $ret; //A e c

##replaceUnacceptableCharacters($string) Clear inputs for build in XML, convert all characters to UTF-8, Replace & isolated, less than, greater than, quotation marks and apostrophes in html entities Remove Carriage Return, Tab and Line Feed Remove Multiple spaces is not acceptable in strings Remove all other control character

NOTE: string may be mixed UTF-8 and Latin1 (iso 8859-1) or Windows-1252

  • @param string $string
  • @return string
    $string = "Contribuições R$   200,00   IPI:   15% Caixa D'agua Rico & Rich < > \"   \t \r \n ";
    $string .= mb_convert_encoding(" teste ç Á ã é ø", 'ISO-8859-1'); 
    $ret = Strings::replaceUnacceptableCharacters($string);
    echo $ret; //Contribuições R$ 200,00 IPI: 15% Caixa D'agua Rico & Rich < > " teste ç Á ã é ø

clearXml()

Remove some attributes, prefixes, sulfixes and other control characters like \r \n \s \t

  • @param string $xml
  • @param boolean $removeEncodingTag default FALSE
  • @return string
    $ret = Strings::clearXml($xml);
    echo $ret; //clean xml will returned

clearProtocoledXML()

Clears the xml after adding the protocol, removing repeated namespaces.

  • @param string $string
  • @return string
    $protxml = Strings::clearProt($xmlstring);
    echo $protxml; //clean xml will returned

deleteAllBetween()

Remove all characters between markers.

  • @param string $string
  • @param string $beginning
  • @param string $end
  • @return string
    $str = '<?xml version="1.0" encoding="UTF-8"?><nfeProc versao="3.10" xmlns="http://www.portalfiscal.inf.br/nfe">
    <NFe xmlns="http://www.portalfiscal.inf.br/nfe">';
    
    $ret = Strings::deleteAllBetween($str, '<?xml', '?>');
    echo $ret; //returns xml without encoding tag

randomString()

Creates a string ramdomically with the specified length.

  • @param int $length
  • @return string
    $randomStr = Strings::randomString(5);
    echo $randomStr; //zRT20

removeSomeAlienCharsfromTxt()

  • Removes [CR] and [TAB]

  • Removes duplicated [spaces]

  • Removes [spaces] after | (pipe)

  • Removes [spaces] before | (pipe)

  • @param string $txt

  • @return string

    $txtclean = Strings::removeSomeAlienCharsfromTxt($txt);
    echo $txtclean; //returns txt without this characters