goodstuff22 Posted December 26, 2010 Share Posted December 26, 2010 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 https://forums.phpfreaks.com/topic/222678-str_replace/ Share on other sites More sharing options...
TwiztedCupid Posted December 26, 2010 Share Posted December 26, 2010 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 https://forums.phpfreaks.com/topic/222678-str_replace/#findComment-1151623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.