Php achieves the original method of interchange between sub-string positions, fontcolor. Php implements the method of interchange of sub-string positions. fontcolor this article describes how php implements interchange of sub-string positions. I would like to share with you the original method of implementing interchange of sub-string positions in php for your reference. fontcolor
This example describes how to swap the positions of sub-strings in php. We will share this with you for your reference. The details are as follows:
<? Php/* substring location swapping */$ str1 = "Tom"; $ str2 = "Jack"; $ str = "This is an example, you see Tom tell Jack something "; function str_change ($ str, $ str1, $ str2) {$ len1 = strlen ($ str1); $ len2 = strlen ($ str2); $ pos1 = strpos ($ str, $ str1); $ str = substr_replace ($ str, $ str2, $ pos1, $ len1); // replace $ str1 with $ str2 $ pos2 = strpos ($ str, $ str2, $ len1 + $ pos1); // locate the position of the original $ str2 field in the string after replacement. return substr_replace ($ str, $ str1, $ pos2, $ len2 ); // replace $ str2 with $ str1} echo str_cha Nge ($ str, $ str1, $ str2);?>
The running result is:
This is an example, you see Jack tell Tom something
Supplement: The editor recommends a php formatting and formatting typographical tool on this site to help you typeset code in future PHP programming:
Php code online formatting and beautification tools:
Http://tools.jb51.net/code/phpformat
In addition, because php belongs to the C language style, the following tool can also format php code:
C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json