简体   繁体   中英

PHP - str_replace

I'm having some trouble using str_replace, this block below

|0460|001|CREDITO SIMPLES NACIONAL|

when I use this:

str_replace("|0460|001|CREDITO SIMPLES NACIONAL|","a", $registroC100, $replaces);

the var $replaces increase, but the text keep the same, I'm doing something wrong?

Edit:

this is how is in my code

$registroC100 = str_replace("|0460|001|CREDITO SIMPLES NACIONAL|","a",$registroC100);

str_replace not changes your variable value unless you do it using the return value of str_replace function.

Take a look at the documentation right here https://www.php.net/manual/pt_BR/function.str-replace.php

<?php
$replaces = 0;
$registroC100 = '|0460|001|CREDITO SIMPLES NACIONAL|';

$registroC100 = str_replace("|0460|001|CREDITO SIMPLES NACIONAL|","a", $registroC100, $replaces);

From your php syntax the str_replace structure and required parameters are okay.

str_replace("|0460|001|CREDITO SIMPLES NACIONAL|","a", $replaces);

It means search the string stored in variable $registroC100, find the value "|0460|001|CREDITO SIMPLES NACIONAL|", replace it with "a" and count the number of replacement in variable $replace. The problem could be from the value of the string you are searching. What is the value of the variable $registroC100. Show us the variable declaration and initialization.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM