tags:

views:

12

answers:

1

I'm trying to get the post-id my posts. this is the format it is in--> postid-785645 the numbers are randomly generated.

<?php
$mysite = "http://example.com";
$wholepage = @file_get_contents($mysite);

// I want to use preg_match to echo just the numbers. out of the whole page.
// Basically i'm trying to have is search the whole page for -> postid-(randomly generated number) and have it echo the number from things that are in this format.

?>
+1  A: 

You could try using the following regular expression:

"/postid-[0-9]+/"

Example code:

$wholepage = 'foo postid-785645 bar postid-785646 baz';
$matches = array();
$string = preg_match_all("/postid-[0-9]+/", $wholepage, $matches);
print_r($matches);

Result:

Array
(
    [0] => Array
        (
            [0] => postid-785645
            [1] => postid-785646
        )

)

I'm using preg_match_all instead of preg_match because preg_match stops after it finds the first match.

Mark Byers
thanks...man.. works nice.
ashoopatel