Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default RE: [PHP] find string

    Isn't there an in_array function you can use?

    If (in_array($action, array(a1,a2,a3,a4)) {
    // do something
    }
    else {
    // do something else
    }


    Carl.

    -----Original Message-----
    From: andu [mailto:php@archeopterix.com]
    Sent: Sunday, August 10, 2003 7:15 PM
    To: [email]php-general@lists.php.net[/email]
    Subject: [PHP] find string

    Here's the problem I have:
    I have $action which can be anyone of a1, a2, a3, a4.
    I tried

    if ($action!='a1' || $action!='a3') //tried == also
    {
    //do stuff
    }
    else
    {
    //do other stuff
    }

    Problem is that if() only seems to take one option so my construct
    above doesn't work.
    What function can I use to do something like:
    if ($action is among the items of 'a2,a4') kind of construct?
    I tried strpos('a1a2a3',$action) but with the same results.
    TIA

    --
    Regards, Andu Novac

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

    Carl Furst Guest

  2. Similar Questions and Discussions

    1. can't find string with quotes
      I'm trying to search for a string that contains quotes and my find statement keeps returning 0 even though I know the string exists in my...
    2. How to find second occurence of a string?
      Hi i am using the find function which will search the first occurence of a string. but how we can find the second or third ...occurence of the...
    3. Find and cut string
      Hi, I'm new to PHP, so please bear with me! =) Is there a nice little function to find a string between to html-tags? I.e. let's say I have a...
    4. find in string
      How can i count the number of times a string appears within another string. Thanks a...
    5. find string between files
      Hi all, how can I search for a specific string inside a directory (between files) ? Thanks for your help
  3. #2

    Default Re: [PHP] find string

    On Sun, 10 Aug 2003 19:27:12 -0400
    "Carl Furst" <carl@vote.com> wrote:
    > Isn't there an in_array function you can use?
    >
    > If (in_array($action, array(a1,a2,a3,a4)) {
    > // do something
    > }
    > else {
    > // do something else
    > }
    >
    >
    > Carl.
    Thanks Carl, if there is no string function for the job I'll have to
    use the array.
    >
    > -----Original Message-----
    > From: andu [mailto:php@archeopterix.com]
    > Sent: Sunday, August 10, 2003 7:15 PM
    > To: [email]php-general@lists.php.net[/email]
    > Subject: [PHP] find string
    >
    > Here's the problem I have:
    > I have $action which can be anyone of a1, a2, a3, a4.
    > I tried
    >
    > if ($action!='a1' || $action!='a3') //tried == also
    > {
    > //do stuff
    > }
    > else
    > {
    > //do other stuff
    > }
    >
    > Problem is that if() only seems to take one option so my construct
    > above doesn't work.
    > What function can I use to do something like:
    > if ($action is among the items of 'a2,a4') kind of construct?
    > I tried strpos('a1a2a3',$action) but with the same results.
    > TIA
    >
    > --
    > Regards, Andu Novac
    >
    > --
    > PHP General Mailing List (http://www.php.net/)
    > To unsubscribe, visit: http://www.php.net/unsub.php
    >
    >
    > --
    > PHP General Mailing List (http://www.php.net/)
    > To unsubscribe, visit: http://www.php.net/unsub.php
    >
    >
    >

    --
    Regards, Andu Novac
    Andu Guest

  4. #3

    Default Re: [PHP] find string

    Hello,

    This is a reply to an e-mail that you wrote on Mon, 11 Aug 2003 at
    00:25, lines prefixed by '>' were originally written by you.
    > Isn't there an in_array function you can use?
    > If (in_array($action, array(a1,a2,a3,a4)) {
    > // do something
    > else {
    > // do something else
    > Carl.
    Make sure that your string values are in quotes or PHP will belooking
    for constants with those names, i.e. array('a1','a2','a3','a4')

    David.

    --
    phpmachine :: The quick and easy to use service providing you with
    professionally developed PHP scripts :: [url]http://www.phpmachine.com/[/url]
    Free PHP error handling script: [url]www.phpmachine.com/error-handler/[/url]

    Professional Web Development by David Nicholson
    [url]http://www.djnicholson.com/[/url]

    QuizSender.com - How well do your friends actually know you?
    [url]http://www.quizsender.com/[/url]
    David Nicholson Guest

  5. #4

    Default Re: [PHP] find string

    On Mon, 11 Aug 2003 10:00:57 +1000 (EST)
    <daniel@electroteque.org> wrote:
    > what exactly is action ?
    >
    > i usually use a action setup like follows
    >
    > ?action=update
    >
    > switch ($_GET['action']) {
    > case 'update':
    > //do stuff here
    > break;
    > case 'insert':
    > //do stuff here
    > break;
    >
    > }
    >
    > very clean
    Action is exactly what you imagine and at some point in the scrip I use
    what you suggest, why I didn't do it here is because I didn't have
    enough coffee today ;-). Nevertheless the previously suggested solution
    using in_array() seems cleaner in this case.
    >
    > > Here's the problem I have:
    > > I have $action which can be anyone of a1, a2, a3, a4.
    > > I tried
    > >
    > > if ($action!='a1' || $action!='a3') //tried == also
    > > {
    > > //do stuff
    > > }
    > > else
    > > {
    > > //do other stuff
    > > }
    > >
    > > Problem is that if() only seems to take one option so my construct
    > > above doesn't work.
    > > What function can I use to do something like:
    > > if ($action is among the items of 'a2,a4') kind of construct?
    > > I tried strpos('a1a2a3',$action) but with the same results.
    > > TIA
    > >
    > > --
    > > Regards, Andu Novac
    > >
    > > --
    > > PHP General Mailing List ([url]http://www.php.net/[/url])
    > > To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    >
    >
    >
    >
    > --
    > PHP General Mailing List ([url]http://www.php.net/[/url])
    > To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    >
    >
    >

    --
    Regards, Andu Novac
    Andu Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139