Replacer Introduction to STRTR functions in PHP str_replace

Source: Internet
Author: User
There are two forms of STRTR:
String Strtr (String $str, String $from, String $to)
String Strtr (string $str, array $replace _pairs)
When the first type is used, the arguments $from, $to string lengths must be the same, otherwise the extra (either $from or $to) characters are ignored.
For example $str = ' a-=b ';
When $from= '-= ', $to = ' CD ', Output ' aCDb ' because '-= ' is the same length as ' CD ', no problem.
When $from= '-= ', $to = ' CDE ', Output ' aCDb ', $to ' E ' is ignored.
When $from= '-= ', $to = ' C ', Output ' ac=b ', $from ' = ' is ignored.
Instead of using the second form, there is no problem, and the extra note is not ignored.
Therefore, if you deliberately replace str_replace with the STRTR function and use the first form, you must pay attention to this feature, which may be a trap.

The above describes the Replacer PHP strtr function use introduced Str_replace, including the replacer aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.