Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Jun 2006
    Location
    eth0
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    get remote content?

    Hi everyone,

    I'm new to the forums, and I hope you'll help me with the problem I have

    I'm creating a vertical newsbar, and I'm trying to get content from a remote page.

    I've tried writing the code with preg_match, but it just doesn't work for me

    The page that I want to extract text from looks like this:
    Code:
    multiple lines of content
    <img src="someimage.jpg">
    multiple lines of content to be extracted
    <div id="something">
    Can somebody take a look at this?

    thx - Matt
    <? print("Hello World") ?>

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The code you are using would be quite handy to see.

    ~Phil~

  • #3
    New Coder
    Join Date
    Jun 2006
    Location
    eth0
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    $news
    "http://www.link.com";
    $handle fopen($news'r');
    while (!
    feof($handle))
    {
    $Data fgets($handle256);
    preg_match('/<img src="someimage.jpg">(.*?)<div id="something">/'$news$matches);

    echo 
    '<pre>';
    print_r($matches);
    echo 
    '</pre>';
    }
    }
    ?>
    <? print("Hello World") ?>

  • #4
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well, normally you cannot fopen a remote url, it's best to use file_get_contents and I have no idea what this $Data is doing there.

    I cannot test, as I don't have the real url, but this is what i'd do...

    PHP Code:
    <?php
    $news
    file_get_contents("http://www.link.com");

    preg_match('@(\<img src\="someimage.jpg"\>).*(?=\<div id\="something"\>)@'$news$matches);

    echo 
    '<pre>';
    print_r($matches);
    echo 
    '</pre>';
    ?>
    Remember, you have to escape regex characters from your search string. They are . \ + * ? [ ^ ] $ ( ) { } = ! < > | : and are escaped with a \.

    ~Phil~

  • #5
    New Coder
    Join Date
    Jun 2006
    Location
    eth0
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, but I get the following error:

    Parse error: syntax error, unexpected T_STRING in host on line 4
    <? print("Hello World") ?>

  • #6
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code executes fine here. What is your line 3, 4 and 5?

    ~Phil~

  • #7
    New Coder
    Join Date
    Jun 2006
    Location
    eth0
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it's just the way you pasted it. and i just copied it
    <? print("Hello World") ?>

  • #8
    New Coder
    Join Date
    Jun 2006
    Location
    eth0
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now I get:

    Array
    (
    )
    <? print("Hello World") ?>

  • #9
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    If you gave me the exact url, it'd be much easier to find the problem.

    ~Phil~

  • #10
    New Coder
    Join Date
    Jun 2006
    Location
    eth0
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PM'ed
    <? print("Hello World") ?>

  • #11
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    No PMs here

    ~Phil~

  • #12
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Oops, ignore that. Just took a while to come.

  • #13
    New Coder
    Join Date
    Jun 2006
    Location
    eth0
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Any ideas?
    <? print("Hello World") ?>


  •  

    Posting Permissions

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