Original method for implementing interchange of sub-string positions in php, fontcolor_PHP tutorial

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.