PHP implementation of sub-string location interchange with each other method original, FontColor
In this paper, we describe the way in which PHP implements the sub-string location interchangeably with each other. Share to everyone for your reference, as follows:
<?php/* Sub-string position Interchange */$str 1= "Tom"; $str 2= "Jack"; $str = "This is a example,you see Tom tell Jack something"; function str_ Change ($str, $str 1, $str 2) { $len 1=strlen ($str 1); $len 2=strlen ($str 2); $pos 1=strpos ($str, $str 1); $str =substr_replace ($str, $str 2, $pos 1, $len 1);//replace $str1 for $STR2 $pos 2= strpos ($str, $str 2, $len 1+ $pos 1);// Locate the position of the $STR2 field after the replacement string return Substr_replace ($str, $str 1, $pos 2, $len 2);//replace $STR2 for $str1}echo Str_change ($STR, $ STR1, $str 2);? >
The result of the operation is:
This is a example,you see Jack tell Tom something
Add: Small make up here to recommend a site of the PHP format beautification of the layout tools to help you in the future of PHP programming code layout:
PHP Code online format Beautification tool:
Http://tools.jb51.net/code/phpformat
In addition, because PHP is a C language style, the following tool can also be used to implement the PHP code format:
C Language Style/html/css/json code formatting beautification tool:
Http://tools.jb51.net/code/ccode_html_css_json
More interested in PHP related content readers can view the site: "PHP Math Skills Summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP array" operation Skills Daquan, " PHP Sorting algorithm Summary, "PHP Common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string Usage Summary" and " A summary of common PHP database operation techniques
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1133029.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133029.html techarticle PHP Implementation of the sub-string location of the interchange method of the original, fontcolor The example of this article describes the PHP implementation of sub-string location exchange between the method. Share to everyone for your reference ...