Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Get contents from website

Comments in 'Plugin Development' started by MyNameIsTriXz, Mar 12, 2016.

  1. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Hey, I tried so many ways to get contents from websites, cURL, getURL() and so on. But everytime it returns null. Can you give me the code to get contents from a website?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Utils::getURL("http://example.com") if you think that function does not work, try dumping this value first.
    MyNameIsTriXz and applqpak like this.
  3. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    PHP:
    /** @var string $contents */
    $contents = \file_get_contents("http://www.example.com");
    This will return the HTML code of a page.
    MyNameIsTriXz and applqpak like this.
  4. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Thanks, but at my last test it did return null, I heard that is because you cant do that with a local hosted server, is that true?
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Are you sure Utils::getURL() returns null directly? It should either return a string, or return boolean false if there was an error. Did you do anything else wrong?
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I will test it today again, does Utils::getURL() return the code or the text on the website?
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The HTTP content payload. A string is just a set of characters. What do you expect if it returns the text on the website? How would the text be like on forums.pocketmine.net? :p
  8. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Uh like that text when I do copy and then choose all? :D Anyways thanks

Share This Page

Advertisement