Gorkfu Posted October 26, 2008 Share Posted October 26, 2008 $old1[] = $word2.','; $old2[] = $word2.'.'; $oldwords = array_merge($old1, $old2); $new1[] = $newwords.','; $new2[] = $newwords.'.'; $newwords = array_merge($new1, $new2); $newtext = str_ireplace($oldwords , $newwords , $oldtext); I have several arrays (Only listed 2 to keep the post simple.) and they all essentially have the same values (words) but with a different character appended to the end. I want to be able to use one array that has the words and then append the characters without modifying the array's values. The goal is to shrink the amount of values down and not need to merge them any more. I couldn't get regexp to work using a preg_replace. Any ideas? Quote Link to comment Share on other sites More sharing options...
Stephen Posted October 26, 2008 Share Posted October 26, 2008 What is $newwords (the first time) and $word2? Also what is $oldtext? Quote Link to comment Share on other sites More sharing options...
Gorkfu Posted October 26, 2008 Author Share Posted October 26, 2008 $oldtext is a paragraph or so of content where I have words replaced. $word2 is a word grabbed from $oldtext and then put inside the arrays with the added charachter on the end. The $old and $new variables go through a loop picking up a different word each time. Lets say these are the values for $oldwords array after the merge: Array ( [0] => word1, [1] => word2, [2] => word3, [3] => word1. [4] => word2. [5] => word3. ) For $newwords it will be essentially the same but with links. Instead of having commas and periods in their I want to append them as I run a replace function. Quote Link to comment Share on other sites More sharing options...
Gorkfu Posted October 27, 2008 Author Share Posted October 27, 2008 The only other way I can see doing this is with the array_walk function, but that would use more memory and I'd still have to merge several arrays. I'm stumped on getting my code cleaner for this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.