Just a short question, will these two lines always give the same result, considering, that an XML request or response is given?
str_replace( array( "\n", "\t", "\r", "\r\n" ), '', trim( $xml ) );
preg_replace( '#>\s+<#', '><', $xml );
If no, how can I make a preg_replace like that?
Thank you in advance.
The
preg_replaceis more constrained than thestr_replace(it only matches whitespace outside angle brackets) and\sincludes the space character. Additionally, a string like<blah> \r \n \t TEXT \t\t</blah>would not be replaced, instead the whitespace would be kept.In fact, the two are nothing alike asides from both affecting whitespace in some way.
The equivalent
preg_replaceto yourstr_replacewould just be('/[\r\n\t]/','',$xml)