Reply to Re: [PHP] Finding first/last occurrence of a substring

Your name:

Reply:


Posted by Bret Hughes on 01/17/05 20:41

On Mon, 2005-01-17 at 09:27, Vikram Vaswani wrote:
> Hi
> 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".
>
> I'm totally lost as to how to do this. Could someone help me out?
>

do you want to replace them or just find the position in the string?
There are functions for both try looking at the manual for
preg_replace:

http://www.php.net/preg_replace

looks like

$replacedstr = preg_replace('/the/','whatever',$origstr,3);

would replace the first three occurances of the with whatever in the
string contained in $origstr and place it in $replacedstr.

HTH
Bret

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация