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
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)

  {

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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