Str_replace is a simple question. thank you.

Source: Internet
Author: User
Str_replace is a simple problem. thank you... for example, $ a = & quot; 123a456a78a9a & quot; replace a with B, but only... if there is no good way... it can be determined that the number of digits before the last a is 12 digits ..... then, replace location a at location 13th. thank you ., P str_replace is a simple problem. thank you...
For example
$ A = "123a456a78a9a"
Replace a with B, but only the last...
If there is no good way to do this, you can determine that the number of digits before the last a is 12. then, you can only replace the 13th position;
Thank you.

------ Solution --------------------
PHP code
Echo strrev (preg_replace ('/a/', 'B', strrev ($ a), 1 ));
------ Solution --------------------
PHP code
Echo preg_replace ('/a [^ a] * $/', 'B', $ );
------ Solution --------------------
The above is wrong.
PHP code
Echo preg_replace ('/a ([^ a] *) $/', 'B $ 1', $ );
Related Article

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.