[Question/Request] Read out Datas from a Website with php? menu

User Tag List

Results 1 to 10 of 10
  1. #1
    sheepking's Avatar Banned
    Reputation
    52
    Join Date
    Nov 2007
    Posts
    690
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Question/Request] Read out Datas from a Website with php?

    Like the title already says(is that right?): I need help with my script. I want to filter out a little thing form a Website. Its a little Box and theres a Motd wich changes daily. Now I want my website to read out the motd and 'simply' show it in that box of my site.

    Here's the code I already made:
    PHP Code:
    <?php
    $url 
    "http://www.schuelervz.net/";

    $startstring '<div id="LeftsideBox">
        <div>
            <p>'
    ;

    $endstring "</p>"

    $file = @fopen ($url,"r");

    if (
    trim($file) == "") {
        echo 
    "Service out of order";
        } else {
        
    $i=0;
        while (!
    feof($file)) {

            
    $zeile[$i] = fgets($file,20000);
            
    $i++;
        }
        
    fclose($file);
    }

    for (
    $j=0;$j<$i;$j++) {
        if (
    $resa strstr($zeile[$j],$startstring)) {
            
    $resb str_replace($startstring""$resa);
            
    $endstueck strstr($resb$endstring);
            
    $result .= str_replace($endstueck,"",$resb);
            
    $result .= "; ";
        }
    }

    $result ".$result";
    return 
    $result;
    ?>

    [Question/Request] Read out Datas from a Website with php?
  2. #2
    Sirupsen's Avatar Member
    Reputation
    25
    Join Date
    Oct 2007
    Posts
    260
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'd probably have to do that by parsing the XML, read about that on W3Schools.
    Link; PHP XML SimpleXML
    (That will only work of course if that website has XML.)
    I don't think there's any other way, if you can't customize that page.



  3. #3
    sheepking's Avatar Banned
    Reputation
    52
    Join Date
    Nov 2007
    Posts
    690
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Sirupsen View Post
    You'd probably have to do that by parsing the XML, read about that on W3Schools.
    Link; PHP XML SimpleXML
    (That will only work of course if that website has XML.)
    I don't think there's any other way, if you can't customize that page.

    Hmm, maybe you're right, but I just want to read the website in [file_get_contents() or fopen()] and then delete code I don't need and just show that part of the string wich goes from

    Code:
    <div id="LeftsideBox">
    to
    Code:
    </p>
    Or I just got an other Idea

    Is it possible to write something with a php-script and also delete the whole thing (or just blend out) what was written before?

  4. #4
    Sirupsen's Avatar Member
    Reputation
    25
    Join Date
    Oct 2007
    Posts
    260
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like, theres something by default, when the PHP script runs, the default stuff get's replaced with something else?



  5. #5
    Lockhead's Avatar Member
    Reputation
    1
    Join Date
    Nov 2008
    Posts
    11
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    easy trick

    it's a very easy task:

    PHP Code:
    <?php
    $url 
    "http://www.schuelervz.net";

    $version phpversion();

    function 
    a_strstr($haystack$needle$before_needle false) {
        if((
    $pos strpos($haystack$needle)) === false) { return false; }
        if(
    $before_needle) { return substr($haystack0$pos strlen($needle)); }
        return 
    substr($haystack,$pos);
    }

    $pat1 '<div id="LeftsideBox">
        <div>
            <p>'
    ;
    $pat2 '<p>';
    $pat3 '</p>    </div>
    </div>
                
            </div>
            <br class="Clear-The-Evil-Float" />'
    ;
    $pat4 '</p>';
    $content file_get_contents($url);
    $content a_strstr($content$pat1false);
    $content a_strstr($content$pat2false);
    $content substr($content3);
    $content a_strstr($content$pat3true);
    $content a_strstr($content$pat4true);
    $content substr($content0strlen($content)-4);
    echo 
    $content;
    ?>
    If you have PHP 5.3.0 installed you can delete the function declaration and have to rename a_strstr to strstr. Because PHP 5.3.0 brings the befor/after flag for this function and so my additional function is noch needed.

  6. #6
    freakyflow's Avatar Contributor
    Reputation
    116
    Join Date
    Jan 2008
    Posts
    275
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The easiest way to do this is with rss and a php rss parser. You barely have to write anything.

    If you site already pushes rss then you just need to get a php rss script and throw in some tags.
    _____________ _ _
    |--|--|==|--|-:_Y


  7. #7
    Lockhead's Avatar Member
    Reputation
    1
    Join Date
    Nov 2008
    Posts
    11
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The Problem here is that the specific site doesn't have a RSS feed for there motd, so sheepking want to leech that info.

    XML Parsing is a really easy task in php and other language too, but that was not the question

  8. #8
    Gravecorp's Avatar Member
    Reputation
    11
    Join Date
    Oct 2008
    Posts
    26
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I sent you a pm. I have done these types of things before. So it shouldn't be so hard to do it again. Just need the site url. What part you need extracted and i will cook you up some code.

  9. #9
    Gravecorp's Avatar Member
    Reputation
    11
    Join Date
    Oct 2008
    Posts
    26
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Solution.

    Here is the working code. I stuck it in a function so you can call it whenever you want to.
    Have fun

    Code:
    function grabHTML() {
    	//Set this value to true to strip out only the <div> tags
    	$stripDivs = false;
    	//Set this value to true to strip out all html tags
    	$stripHtml = false;
    	//The 2 values below are used for the script.
    	$html = "";
    	$boolLeftSideBox = false;
    	//Open the site and start reading.
    	$website = file('http://www.schuelervz.net/Default');
    	foreach($website as $line) {
    		if(eregi('<div id="LeftsideBox">', $line)) {
    			$boolLeftSideBox = true;
    			continue;
    		}
    		if($boolLeftSideBox) {
    			if(eregi('<div>', $line)) {
    				$html .= $line;
    			} else {
    				$html .= $line;
    				if($stripDivs) {
    					$html = str_replace('<div>', '', $html);
    					$html = str_replace('</div>', '', $html);
    				}
    				if($stripHtml) {
    					$html = strip_tags($html);
    				}
    				return $html;
    			}
    		}
    	}
    }
    
    echo grabHTML();

  10. #10
    sheepking's Avatar Banned
    Reputation
    52
    Join Date
    Nov 2007
    Posts
    690
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very, very good!

    Works!

    Thank you very much!

    +rep x2

    (Just the prob that I'm using a Free hoster wich is forbidding the most of your arguments, but works fine with xampp)

Similar Threads

  1. [Question] Reading DBC's from memory?
    By -Ryuk- in forum WoW Memory Editing
    Replies: 7
    Last Post: 09-05-2011, 04:52 PM
  2. Replies: 18
    Last Post: 08-05-2011, 02:14 PM
  3. [Question] reading static address from cheat engine
    By gononono64 in forum WoW Memory Editing
    Replies: 15
    Last Post: 01-06-2011, 11:27 PM
  4. [Question/Request] Buying from vendors?
    By ZomgZippo in forum WoW Bots Questions & Requests
    Replies: 0
    Last Post: 05-26-2010, 03:18 PM
  5. StormDLL? Reading data from MPQ files?
    By Tanaris4 in forum WoW Memory Editing
    Replies: 4
    Last Post: 10-06-2009, 09:53 AM
All times are GMT -5. The time now is 04:14 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search