string contains a substring

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hokieghal99

    string contains a substring

    How does one tell if a string contains a certain substring?

    For example:

    $a = popen("/bin/ping -c1 $rhost", "r");
    $read = fread($a, 1024);
    pclose($a);
    if($read contains "1 received")
    {
    print "Ping Succeded";
    }
    else
    {
    print "Ping Failed";
    }



  • Pedro Graca

    #2
    Re: string contains a substring

    hokieghal99 wrote:[color=blue]
    > How does one tell if a string contains a certain substring?
    >
    > For example:
    >
    > $a = popen("/bin/ping -c1 $rhost", "r");
    > $read = fread($a, 1024);
    > pclose($a);[/color]

    if (strpos($read, '1 received') !== false) {
    // do not use != instead!!
    echo 'Ping Succeded';
    } else {
    echo 'Ping Failed';
    }

    Find the position of the first occurrence of a substring in a string



    and, since you're already reading the manual, check all other string
    functions :)

    Find the position of the first occurrence of a substring in a string

    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • CountScubula

      #3
      Re: string contains a substring

      "hokieghal9 9" <hokiegal99@hot mail.com> wrote in message
      news:btf4ad$400 $1@solaris.cc.v t.edu...[color=blue]
      > How does one tell if a string contains a certain substring?
      >
      > For example:
      >
      > $a = popen("/bin/ping -c1 $rhost", "r");
      > $read = fread($a, 1024);
      > pclose($a);
      > if($read contains "1 received")
      > {
      > print "Ping Succeded";
      > }
      > else
      > {
      > print "Ping Failed";
      > }
      >
      >
      >[/color]

      Pssst. Ping doesnt work on on machines, sometimes php wont let you execute
      a system command,
      try this:


      --
      Mike Bradley
      http://www.gzentools.com -- free online php tools


      Comment

      • hokieghal99

        #4
        Re: string contains a substring

        Pedro Graca wrote:[color=blue]
        > hokieghal99 wrote:
        >[color=green]
        >>How does one tell if a string contains a certain substring?
        >>
        >>For example:
        >>
        >> $a = popen("/bin/ping -c1 $rhost", "r");
        >> $read = fread($a, 1024);
        >> pclose($a);[/color]
        >
        >
        > if (strpos($read, '1 received') !== false) {
        > // do not use != instead!!
        > echo 'Ping Succeded';
        > } else {
        > echo 'Ping Failed';
        > }
        >
        > http://www.php.net/strpos
        >
        >
        > and, since you're already reading the manual, check all other string
        > functions :)
        >
        > http://www.php.net/manual/en/function.strpos.php[/color]

        That works great. Thanks for the string info... I'll read up on it!

        Comment

        • hokieghal99

          #5
          Re: string contains a substring

          CountScubula wrote:[color=blue]
          > Pssst. Ping doesnt work on on machines, sometimes php wont let you execute
          > a system command,
          > try this:
          > http://www.gzentools.com/snippetview...=fuzzyping.php
          >
          > --
          > Mike Bradley
          > http://www.gzentools.com -- free online php tools[/color]

          Umm... it works on mine... no problem at all. Why do you say this???

          Comment

          • CountScubula

            #6
            Re: string contains a substring

            "hokieghal9 9" <hokiegal99@hot mail.com> wrote in message
            news:btf7hs$9a7 $2@solaris.cc.v t.edu...[color=blue]
            > CountScubula wrote:[color=green]
            > > Pssst. Ping doesnt work on on machines, sometimes php wont let you[/color][/color]
            execute[color=blue][color=green]
            > > a system command,
            > > try this:
            > > http://www.gzentools.com/snippetview...=fuzzyping.php
            > >
            > > --
            > > Mike Bradley
            > > http://www.gzentools.com -- free online php tools[/color]
            >
            > Umm... it works on mine... no problem at all. Why do you say this???
            >[/color]

            I meant some machines, not all.

            There was another post a couple of days ago, somone wanted to have the ping
            to user time in his script, but was unable to run system commands (php was
            locked down)

            I originaly posted a ping code snippet, but it didnt work for him, so I
            wrote that workaround.

            --
            Mike Bradley
            http://www.gzentools.com -- free online php tools


            Comment

            Working...