Search for string and then take string next to it.

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

    #1

    Search for string and then take string next to it.

    Hi,

    What I'm looking for is a way for php to retrieve a webpage, search for a
    string in it, and next to that will be a date string in the format (e.g.)
    03-Sep-04 22:37:40 BST, and then I'd like PHP to store that as a date/time
    variable (preferably using unix timestamp)...

    This possible?

    Thanks,

    Ben
    --
    BWGames
    to email change de.news to de-news
  • BWGames

    #2
    Re: Search for string and then take string next to it.

    On Mon, 1 Nov 2004 08:14:58 +0000, BWGames wrote:
    [color=blue]
    > Hi,
    >
    > What I'm looking for is a way for php to retrieve a webpage, search for a
    > string in it, and next to that will be a date string in the format (e.g.)
    > 03-Sep-04 22:37:40 BST, and then I'd like PHP to store that as a date/time
    > variable (preferably using unix timestamp)...
    >
    > This possible?
    >
    > Thanks,
    >
    > Ben[/color]

    Also, the timezone is irrelevant, I just need a way of identifying dd-mm-yy
    hh:mm:ss as a php date/time stamp to perform time calculations on it...
    --
    BWGames
    to email change de.news to de-news

    Comment

    • Adam Harvey

      #3
      Re: Search for string and then take string next to it.

      On Mon, 01 Nov 2004 08:14:58 +0000, BWGames wrote:
      [color=blue]
      > What I'm looking for is a way for php to retrieve a webpage, search for a
      > string in it, and next to that will be a date string in the format (e.g.)
      > 03-Sep-04 22:37:40 BST, and then I'd like PHP to store that as a date/time
      > variable (preferably using unix timestamp)...
      >
      > This possible?[/color]

      Parse about any English textual datetime description into a Unix timestamp


      Adam

      --
      Adam Harvey
      Optimiser Pty Ltd

      To e-mail: don't make an example out of me!

      Comment

      • BWGames

        #4
        Re: Search for string and then take string next to it.

        On Mon, 01 Nov 2004 16:29:35 +0800, Adam Harvey wrote:
        [color=blue]
        > On Mon, 01 Nov 2004 08:14:58 +0000, BWGames wrote:
        >[color=green]
        >> What I'm looking for is a way for php to retrieve a webpage, search for a
        >> string in it, and next to that will be a date string in the format (e.g.)
        >> 03-Sep-04 22:37:40 BST, and then I'd like PHP to store that as a date/time
        >> variable (preferably using unix timestamp)...
        >>
        >> This possible?[/color]
        >
        > http://www.php.net/strtotime
        >
        > Adam[/color]

        Thanks!

        I now need to search for a string and return the next X characters to
        it....

        I'm guessing I'd use libcurl or similar to retrieve the webpage, and them
        do strpos to find the string, but how to get the characters next to it?

        I'm looking at
        between... sometihng like between
        between ('string1', 'string after what i want',$retrieve dpage);

        then strtotime...
        That the best way?

        Thanks,
        ben
        --
        BWGames
        to email change de.news to de-news

        Comment

        • Pedro Graca

          #5
          Re: Search for string and then take string next to it.

          BWGames wrote:[color=blue]
          > I now need to search for a string and return the next X characters to
          > it....[/color]
          [snip][color=blue]
          > I'm looking at
          > between... sometihng like between
          > between ('string1', 'string after what i want',$retrieve dpage);[/color]


          <?php
          function text_after($hay stack, $needle, $size) {
          $pos = strpos($haystac k, $needle);
          if ($pos === false) return false;
          return substr($haystac k, $pos+strlen($ne edle), $size);
          }

          $text = 'one two three four five six seven';

          $found = text_after('thr ee', 5, $text);
          if ($found === false) echo "Not found\n";
          else echo 'Found: ', $found, "\n";
          ?>
          --
          USENET would be a better place if everybody read: | to mail me: simply |
          http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
          http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
          http://www.expita.com/nomime.html | and *NO* attachments. |

          Comment

          • Pedro Graca

            #6
            Re: Search for string and then take string next to it.

            Pedro Graca wrote:[color=blue]
            > <?php
            > function text_after($hay stack, $needle, $size) {
            > $pos = strpos($haystac k, $needle);
            > if ($pos === false) return false;
            > return substr($haystac k, $pos+strlen($ne edle), $size);
            > }
            >
            > $text = 'one two three four five six seven';
            >
            > $found = text_after('thr ee', 5, $text);[/color]

            Oops, this last line should have been

            $found = text_after($tex t, 'three', 5);
            [color=blue]
            > if ($found === false) echo "Not found\n";
            > else echo 'Found: ', $found, "\n";
            > ?>[/color]
            --
            USENET would be a better place if everybody read: | to mail me: simply |
            http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
            http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
            http://www.expita.com/nomime.html | and *NO* attachments. |

            Comment

            Working...