Jump to content

str_replace multiple replacements error


anarchoi

Recommended Posts

here is my code:

 

$xi = $ix + 1;

$one = array("2002", "12012", "13013", "17017");

$two = array("one", "two", "three", "four");

$realnames = str_replace($one, $two, $realnumbers);

 

 

$realnumbers2 = $ix + 1;

$realnumbers = $realnumbers2 * 1000 + $realnumbers2;

      echo "$realnames \n";

echo "<br>( $realnumbers )";

  }

  else

  {

//      echo "Option $ix was NOT selected<br />\n"; //

  }

}

 

the replacements works, but the last entry isn't displayed (17017/four in this code)

 

i.e. $realnumbers = 2002 12012 13013 17017

 

only the three first will be displayed/replaced as soon as i use str_replace with $realnumbers :/ ...weird

Link to comment
https://forums.phpfreaks.com/topic/94449-str_replace-multiple-replacements-error/
Share on other sites

yeah, i forgot to add the beginning of the script

 

it's comming from $ix ... i am doing *1000 +$ix just so the numbers always look differents and its easier for the replacement (or else if i replace a 2 it would replace 222, 202, 12222, etc)

 

$nbr = 21;

$selected = $post[field7];

for($ix = 0; $ix < $nbr; $ix++)

{

  if(pow(2, $ix) & $selected)

  {

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.