How to replace strings

Source: Internet
Author: User
How can I replace a string? $ A = & quot; 1234683214312354436214214125436121436 & quot; $ B = & quot; 76234265832465867892353463476254273434252 & quot; replace the middle 1 of $ a '@'; for example, how does one replace the string with 6th in 11 cases?
$ A = "1234683214312354436214214125436121436 ";
$ B = "76234265832465867892353463476254273434252 ";

Replace the middle 1 of $ a with '@'. for example, if there are 11 1 s, replace 6th.
Replace the middle 2 in $ B with '@'. for example, if there are eight 2 S, replace 4th.

------ Solution --------------------
You can use preg_match_all + PREG_OFFSET_CAPTURE to match the information you want to replace and the offset of the matching information. what do you know next.
$ A = "1234683214312354436214214125436121436 ";
$ B = "76234265832465867892353463476254273434252 ";
Preg_match_all ('#1 #', $ a, $ match, PREG_OFFSET_CAPTURE );
Echo"
"; 

Print_r ($ match );
?>
------ Solution --------------------
Discussion

Reference:
No error reported twice. I fixed it.


PHP code

Function fool ($ str, $ number, $ change)
{

$ Array = str_split ($ str );
If (in_array ($ number, $ array )){
$ Key = array_keys ($ array, $ number );
$ ......

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.