legohead6 Posted August 1, 2006 Share Posted August 1, 2006 how i cannot find a function! i want to cut these letters out then put them into another string in the order the were cut!EDIT: by "these" i mean like an array of lettersor how to find all letters that were changed by str_replace... Link to comment https://forums.phpfreaks.com/topic/16165-cutting-letters-out-of-a-string/ Share on other sites More sharing options...
trq Posted August 1, 2006 Share Posted August 1, 2006 Your not being very clear. Maybe your looking for [url=http://php.net/substr]substr[/url](), but really... who knows. Link to comment https://forums.phpfreaks.com/topic/16165-cutting-letters-out-of-a-string/#findComment-66818 Share on other sites More sharing options...
legohead6 Posted August 1, 2006 Author Share Posted August 1, 2006 k i have an array or letters..(lets say $letters) and i have a sentence (say $text) I want to have it go through the sentance and find all the letters in the $letter array and remove them from the sentance. Then make them into there own array(called $removedletters) Link to comment https://forums.phpfreaks.com/topic/16165-cutting-letters-out-of-a-string/#findComment-66822 Share on other sites More sharing options...
trq Posted August 1, 2006 Share Posted August 1, 2006 Probably better ways around, but....[code=php:0]<?php $letters = array('a','b','c','d'); $text = "this is a big bad string"; foreach($letters as $letter) { if (strpos($text,$letter)) { $removedletters[] = $letter; $text = str_replace($letter,"",$text); } } echo "the letters ".implode(" ",$removedletters)." were removed from '$text'";?>[/code] Link to comment https://forums.phpfreaks.com/topic/16165-cutting-letters-out-of-a-string/#findComment-66823 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.