Connecting Tech Pros Worldwide Forums | Help | Site Map

Search for string and then take string next to it.

BWGames
Guest
 
Posts: n/a
#1: Jul 17 '05
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
Guest
 
Posts: n/a
#2: Jul 17 '05

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
Adam Harvey
Guest
 
Posts: n/a
#3: Jul 17 '05

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]

http://www.php.net/strtotime

Adam

--
Adam Harvey
Optimiser Pty Ltd

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

BWGames
Guest
 
Posts: n/a
#4: Jul 17 '05

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',$retrievedpage);

then strtotime...
That the best way?

Thanks,
ben
--
BWGames
to email change de.news to de-news
Pedro Graca
Guest
 
Posts: n/a
#5: Jul 17 '05

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',$retrievedpage);[/color]


<?php
function text_after($haystack, $needle, $size) {
$pos = strpos($haystack, $needle);
if ($pos === false) return false;
return substr($haystack, $pos+strlen($needle), $size);
}

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

$found = text_after('three', 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. |
Pedro Graca
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Search for string and then take string next to it.


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

Oops, this last line should have been

$found = text_after($text, '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. |
Closed Thread