Re: Counting the number of occurrences (and position) of of a char in a string

From: Chung Leong (chernyshevsky_at_hotmail.com)
Date: 01/29/05


Date: Sat, 29 Jan 2005 12:09:52 -0500


<francescomoi@europe.com> wrote in message
news:1107010324.494830.277500@f14g2000cwb.googlegroups.com...
> Hi.
>
> I'm using 'strpos', but wonder whether this function exists:
> find_string($haystack, $needle)
> which returns an array with all the numeric positions of the
> occurrences of needle in the haystack.
>
> Thank you very much.
>

preg_match_all() with the PREG_OFFSET_CAPTURE flag. Not quite the same as a
simple text search but never hurts to have more power.



Relevant Pages

  • cant use an array property of a user control in designer?
    ... I have a user control and I want an array of items to be available to ... In my case these items are a class called Needle. ... public class MultiNeedleSlider: System.Windows.Forms.UserControl ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Newbie array question
    ... array_search -- Searches the array for a given value and returns the ... mixed array_search (mixed needle, array haystack [, bool strict]) ... Searches haystack for needle and returns the key if it is found in the ...
    (comp.lang.php)
  • Re: GetCrossReferenceItems is acting flakey
    ... You have not even shown us the haystack in which you would like us to find the needle. ... Please reply to the newsgroup unless you wish to avail yourself of my ... Doug Robbins - Word MVP, ... I then unpack the array into my form list ...
    (microsoft.public.word.vba.general)
  • Re: is there anything like IN (val1,val2,val3)
    ... yields true, although the "needle" is of type number, and the haystack ... has only a value of type string. ... However, the Array ...
    (comp.lang.javascript)
  • Issues with strpos
    ... Not quite sure what's happening here, the docs for strpos() say: ... If needle is not found, ... "This function may return Boolean FALSE, but may also return a non- ... array then doing an array find or something. ...
    (comp.lang.php)