Jump to content

Recommended Posts

I have kind of a dumb question, but is there some way to clear what I have just echo after a certain amount of time? I have my script and I tried to delay it by using sleep and it just delay the time it took to load the webpage lol.

 

Thanks

~AJ

 

	$fp = fsockopen("$server", $port, $errno, $errstr, 30);
	fputs($fp, "GET /admin.cgi?pass=".$password."&mode=viewxml HTTP/1.0\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)\r\n\r\n");
	while (!feof($fp)) {
		$content = fgets($fp);
	}
	$pattern = "/<SONGTITLE>(.*?)<\/SONGTITLE>/si";
	preg_match($pattern, $content, $matches);
	echo $matches[1];

Link to comment
https://forums.phpfreaks.com/topic/207865-clear-screen/
Share on other sites

<script type="text/javascript">
function hide(){
document.getElementById('hideme').style.display = 'none';
}
function sethide(){
setTimeout("hide()",5000);
}
</script>

<div onload=\"sethide()\" id=hideme>YOUR STUFF TO HIDE</div>

 

will hide it within 5 seconds

 

Should work ....  :shrug:

Link to comment
https://forums.phpfreaks.com/topic/207865-clear-screen/#findComment-1086638
Share on other sites

I don't really want to hide it but, I was googling around and there is a cool guy from youtube who said:

 

The easiest way to "clear screen" is pretty ghetto but it works. Just echo new lines where you want to clear the screen =P.

while(true){
for ($i=0;$i<30;$i++){
echo "rn";
}
}

 

But it doesn't really work for me.

 

I just want to echo the new data over the old. It's only one line but it should work.

 

	$fp = fsockopen("$server", $port, $errno, $errstr, 30);
	fputs($fp, "GET /admin.cgi?pass=".$password."&mode=viewxml HTTP/1.0\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)\r\n\r\n");
	while (!feof($fp)) {
		$content = fgets($fp);
	}
	$pattern = "/<SONGTITLE>(.*?)<\/SONGTITLE>/si";
	preg_match($pattern, $content, $matches);
	echo $matches[1];

 

I just need to learn how to make the script pause before starting up again. The only thing with sleep command is it just holds up the webpage from loading during the seconds it is waiting  :-\

Link to comment
https://forums.phpfreaks.com/topic/207865-clear-screen/#findComment-1086751
Share on other sites

When a PHP script is run it doesn't send the page to the browser until it is done processing. You can't send a page tothe browser then have PHP interact with that page by itself. THe user needs to initiate some action to ask the server for new information such as the user clicking a link or JavaScript running in the client's browser that will initiate the request.

 

So, you need a client-side solution. But, in this case, even JavaScript is not needed since there is a simple HTML solution. The meta refresh tag.

<meta http-equiv="refresh" content="10;url=http://www.domain.com/pagetoredirect.php">

 

Put a line like that in the HEAD section of the HTML page and after 10 seconds it will refresh the page by opening the URL http://www.domain.com/pagetoredirect.php

Link to comment
https://forums.phpfreaks.com/topic/207865-clear-screen/#findComment-1086781
Share on other sites

When a PHP script is run it doesn't send the page to the browser until it is done processing. You can't send a page tothe browser then have PHP interact with that page by itself. THe user needs to initiate some action to ask the server for new information such as the user clicking a link or JavaScript running in the client's browser that will initiate the request.

 

So, you need a client-side solution. But, in this case, even JavaScript is not needed since there is a simple HTML solution. The meta refresh tag.

<meta http-equiv="refresh" content="10;url=http://www.domain.com/pagetoredirect.php">

 

Put a line like that in the HEAD section of the HTML page and after 10 seconds it will refresh the page by opening the URL http://www.domain.com/pagetoredirect.php

 

I just don't want to have to use a iframe or refresh the page. I'm keep looking for an answer.

Link to comment
https://forums.phpfreaks.com/topic/207865-clear-screen/#findComment-1086875
Share on other sites

I found a script but it doesn't do much except display my part of my code lol.

 

Returns:

(.*?)<\/SONGTITLE>/si"; preg_match($pattern, $content, $matches); echo $matches[1]; //sleep(2); //} ?>

 

Index.php

<script src="ajax.js"></script>

<script type="text/javascript">
refreshdiv_parserdiv();
</script>
<div name="parserdiv" id="parserdiv"></div>

 

AJAX.JS

// The AJAX function...

function AJAX(){
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
return xmlHttp;
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
return xmlHttp;
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}
}

// Timestamp for preventing IE caching the GET request (common function)

function fetch_unix_timestamp()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}

////////////////////////////////
//
// Refreshing the parser
//
////////////////////////////////

function refreshdiv_parserdiv(){

// Customise those settings

var seconds = 5;
var divid = "timediv";
var url = "xml grabber.php";

// Create xmlHttp

var xmlHttp_one = AJAX();

// No cache

var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;

// The code...

xmlHttp_one.onreadystatechange=function(){
if(xmlHttp_one.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp_one.responseText;
setTimeout('refreshdiv_timediv()',seconds*1000);
}
}
xmlHttp_one.open("GET",nocacheurl,true);
xmlHttp_one.send(null);
}

// Start the refreshing process

window.onload = function startrefresh(){
setTimeout('refreshdiv_timediv()',seconds*1000);
}

 

xml grabber.php

	$fp = fsockopen("$server", $port, $errno, $errstr, 30);
	fputs($fp, "GET /admin.cgi?pass=".$password."&mode=viewxml HTTP/1.0\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)\r\n\r\n");
	while (!feof($fp)) {
		$content = fgets($fp);
	}
	$pattern = "/<SONGTITLE>(.*?)<\/SONGTITLE>/si";
	preg_match($pattern, $content, $matches);
	echo $matches[1];

Link to comment
https://forums.phpfreaks.com/topic/207865-clear-screen/#findComment-1086881
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.