Jump to content

Append Charachters To Array Values


Gorkfu

Recommended Posts

  $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?

Link to comment
Share on other sites

$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.

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.