Jump to content

str_replace


goodstuff22

Recommended Posts

more test

 

--

==================================================================

this mobile text message is brought to you by at&t

 

How can I get the red part removed?

 

I tried:

 

$endings = array('\n--\n==================================================================\nthis mobile text message is brought to you by at&t');
$CONTENT = str_replace($endings,"",$CONTENT);

 

i put it in an array because i'll have to add more things later

Link to comment
Share on other sites

Not 100% on this one but you can try...

 

$endings = array("\n--\n==================================================================\nthis mobile text message is brought to you by at&t", "blue", "green");
$replace_text= "\n--\n==================================================================\nthis mobile text message is brought to you by at&t";
$replacement = "";
for($i=0;$i<count($endings);$i++) {
   if($endings[$i] == $replace_text) {
   $endings[$i] = $replacement;
   }
}
print_r($endings);

This will find that text and remove it where ever it is in your array. It will however leave a blank spot in your array. I added "blue" and "green" to show what would happen if you added more stuff to the array.

OUTPUT:

Array ( [0] => [1] => blue [2] => green )

 

Or you can try.....

$endings = array("\n--\n==================================================================\nthis mobile text message is brought to you by at&t", "blue" , "green");
unset($endings[0]);
print_r($endings);

This will remove the first entry in the array. If your red text is always in that position then this should also work.

OUTPUT:

Array ( [1] => blue [2] => green ) 

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.