RE: Finding first/last occurrence of a substring

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[snip]
I have a string like this:
----
Just when you begin to think the wagon of Vietnam-grounded movies is
grinding to a slow halt, you're hit squarely in the face with another
one. However, while other movies depict the gory and glory of war and
its effects, this centres on the psychology of troopers before they're
led to battle.
----
I need to know the index position of every occurrence of the pattern
"the" in the string above, and replace it with something else.
Specifically, I need the position of the last, first and third
occurrences of "the".
[snip]

Something like ...

$stringArray = explode(' ', $theString);
for ($i = 0; $i < count($stringArray); $i++){
	if("the" == $stringArray[$i]){
		$newStringArray[$i] = "replacing the";
	} else {
		$newStringArray[$i] = $stringArray;
	}
}
$myNewString = implode(' ', $newStringArray); 

NOT tested

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux