SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Retrieving data from a document

    My goal is to retrieve info from a document. An example would be XML or HTML. I have come up with a few ideas; however, they all seem somewhat uneffecient.

    Example:
    Code:
    <html>
    <head>
    <title>Document name</title>
    </head>
    <body>
    some contents
    </body>
    </html>
    Then the script gets what's between the <title> and <body> tags. I thought I could use something like below, but I decided against it (if i can get better).

    PHP Code:
    $string "html";
    $title_pre explode("<title>"$string);
    $title explode('</title>'$title_pre['1']);
    $title $title['0']; 
    If you're not part of the solution, you're part of the problem.

    If you're constantly waiting for the weekend,
    you're missing out on 5/7 of your life.

  2. #2
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just use preg_match

    PHP Code:
     preg_match('#<title>(.*?)</title>#'$string$match);
     
     
    $title $match[1]; 

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahhhh. I will use that one, thank you Jump!

    I'm probably going to use preg_match, but if anyone knows of a better method, feel free to tell me! =)

    Thanks
    If you're not part of the solution, you're part of the problem.

    If you're constantly waiting for the weekend,
    you're missing out on 5/7 of your life.

  4. #4
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the body contents you might want to use this.

    PHP Code:
    $start_code strpos($string'<body>') + 6;
     
    $end_code =  strpos($string'</body>');
     
    $code_length $end_code $start_code;
     
     
    $body substr($string$start_code$code_length); 

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jump!
    If you're not part of the solution, you're part of the problem.

    If you're constantly waiting for the weekend,
    you're missing out on 5/7 of your life.


Bookmarks

Posting Permissions

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