The example of this article is about how to swap the position of the substring in PHP. Share to everyone for your reference, specific as follows:
<?php
/* substring position swap
* * *
$str 1= "Tom";
$str 2= "Jack";
$str = "This is a example,you to 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); Position return
substr_replace ($str, $str 1, $pos 2, $len 2) of the $str2 field after the replacement of the string;/replace $STR2 with $STR1
}
Echo str_ Change ($str, $str 1, $str 2);
? >
The results of the operation are:
This is a example,you, Jack tell Tom something
Add: small knitting here recommend a site for the layout of the PHP format landscaping tools to help you in the future of PHP programming code layout:
PHP code online format Landscaping tools:
Http://tools.jb51.net/code/phpformat
In addition, because PHP belongs to the C language style, the following tool can also be used to format PHP code:
C Language Style/html/css/json code formatting landscaping Tools:
Http://tools.jb51.net/code/ccode_html_css_json
More interested in PHP related content readers can view the site topics: "PHP Math Arithmetic Skills summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP Array" operation Skills Encyclopedia, " Summary of the PHP sorting algorithm, "PHP commonly used 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 (String) Usage summary" and " A summary of common PHP database operations tips
I hope this article will help you with the PHP program design.