Jump to content

Memo to webpage


Xeno

Recommended Posts

Would it be possible to get text from a website and insert it on a memo automatically?

So say if I had a webpage with just text on it, and edited it a bit, it would automatically change the memo ingame.

Is this possible? If so, please tell me how ;3

Thanks,

Xeno.

Link to comment
It is possible, use callRemote, PHP and setTimer every time.

callRemote + setTimer = Suicide :mrgreen:

If you want get a text from your website, try something like that

Client-side:

  
thememo = guiCreateMemo(0.5,0.5,1,1, "", false) 
  
addEvent("WriteOnTheMemo", true) 
addEventHandler("WriteOnTheMemo", getRootElement(), 
function(text) 
    if text then 
        guiSetText(thememo, tostring(text)) 
    end 
end) 
  

Server side:

  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 
function() 
    setTimer(getWebsite, 10000, 0) 
end) 
  
function result(content) 
    if content then 
        triggerClientEvent("WriteOnTheMemo", getRootElement(), content) 
    end 
end 
  
function getWebsite() 
    local tralala = 1 
    callRemote("http://www.yourwebsite.com/file.php", result, tralala) 
end 
  
  

<?php 
    include("mtalibrary.php"); 
     
    $input = mta::getInput(); 
    $tralala = $input[0]; 
     
    if($tralala == 1){ 
        // You get your informations about your website etc 
        // and you return the content 
        $content = "My website !"; 
         
        mta::doReturn($content); 
    } 
     
?> 
  
  

Edited by Guest
Link to comment
With that example Fatal, if I had a blank webpage with "hello" on it, it would show up in the Memo as "Hello"??

Hm yes it's possible.

But it will be plain text :roll:

You can do it using the PHP function file_get_contents

Look this example i made:

<?php 
    // PHP File 
    $content = file_get_contents('mypage.php'); 
     
    if(isset($content)){ 
        echo html2text($content); 
    } 
    else{ 
        echo "No content "; 
    } 
     
    function html2text($html) 
    { 
        $tags = array ( 
        0 => '~<h[123][^>]+>~si', 
        1 => '~<h[456][^>]+>~si', 
        2 => '~<table[^>]+>~si', 
        3 => '~<tr[^>]+>~si', 
        4 => '~<li[^>]+>~si', 
        5 => '~<br[^>]+>~si', 
        6 => '~<p[^>]+>~si', 
        7 => '~<div[^>]+>~si', 
        ); 
        $html = preg_replace($tags,"\n",$html); 
        $html = preg_replace('~</t(d|h)>\s*<t(d|h)[^>]+>~si',' - ',$html); 
        $html = preg_replace('~<[^>]+>~s','',$html); 
        // reducing spaces 
        $html = preg_replace('~ +~s',' ',$html); 
        $html = preg_replace('~^\s+~m','',$html); 
        $html = preg_replace('~\s+$~m','',$html); 
        // reducing newlines 
        $html = preg_replace('~\n+~s',"\n",$html); 
        return $html; 
    } 
?> 

It work perfectly...

pageloader.jpg

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...