Page 2 of 2

Posted: Wed Feb 05, 2003 12:56 pm
by Nik
Can u show it to me in javascript show that i can see the difference! u r right ita takes a lot of computing time in web server!!!

Posted: Wed Feb 05, 2003 1:09 pm
by Nik
// if you want to enable "re-writing" you need something like
// else
// $_SESSION['i']=0; --or-- session_destroy(); here


the script u gave me with session worked very cool but
only once! when i tryied it again it just popped up the whole string!

Any ideas how to correct this?

Posted: Wed Feb 05, 2003 1:19 pm
by volka

Code: Select all

if(strlen($keimeno) == $_SESSION['i'])
   header("Refresh: 1; URL=http://localhost/test.php");
else
   session_destroy();
Also wrote a little typer-script in js

Code: Select all

<html>
<head>
	<script type="text/javascript">
		var textToShow = "just a test";
		var pos = 0;
		var tm;
		
		function init()
		{
			tm = setInterval("type()", 200);
		}
		
		function type()
		{
			if (textToShow.length != pos)
			{
				d = document.getElementById("divText");
				d.appendChild(document.createTextNode(textToShow.charAt(pos++)));
			}
			else
				clearInterval(tm);
		}
	</script>
</head>
<body onload="javascript:init();">
	<div id="divText" style="border: 5px solid yellow; width: 200px; height: 50px;">
	</div>
</body>
</html>
not very sophisticated and it needs domhtml support (so it's limited to newer browsers) but works here in ie6 and mozilla 1.2

Posted: Wed Feb 05, 2003 1:31 pm
by Nik
Yes it wokrs great too and i think that u can se the spedd in this one!!!
cool!

But can u pls tell mw how can i insert thsi to the previous php code u gave me so that i can it all in one?? i dont knwo if iam sking this correctly but the reasone for all this is:

http://www.nikolas.tk

the text that u see in the table i want it to be display one by one character using the js script u gave me so pls tell me how to insert this code to read from my file!!

Thank u very much!! here is my inde.php that i want your js script to be inserted!!

<?php
error_reporting(E_ALL); $xronos=date("l dS of F h:i:s A"); $host=gethostbyaddr($_SERVER['REMOTE_ADDR']); $i=0;

if (@mysql_connect('localhost', 'nik', 'macgyver'));
else @mysql_connect('localhost', 'root');
mysql_select_db('db_nik');

if ($host=="komodino.itc.auth.gr") echo "ÂñÝ êáëþò ôïí ×ñÞóôï! ×áßñïìáé ðïõ óå âëÝðù ðÜëé! Óáí ôï óðßôé óïõ!<p>";

$file_data = file("data.txt");
$file_diary = file("diary.txt");
?>

<body bgproperties='fixed' background='pics/anemos.bmp'>
<form action="show.php" method="post">
<center><font size='5' color='LightGreen'>- Ðñïò íÝïí åñùôÞóáíôá ðåñß ðñïóåõ÷Þò -</font></center><br>

<center><table border='1' cellspacing='1' width='90%' id='AutoNumber1' bordercolor='Yellow' style='border-style: solid; border-width: 5' background='pics/brick.jpg'>
<tr>
<td align=center bordercolor='#ffcc00'> <font face='Com' size='4' color='LightBlue'><? while ($i < count($file_data)) echo $file_data[$i++]; ?></font></td>
</tr>
</table>

<p>
<center><font size='4' color='Cyan'>* Áí èÝëåéò íá êÜíåéò êáé óõ ìéá äùñåÜ ðñïò óõíáíèñþðïõò ðïõ Ý÷ïõí ôçí áíÜãêç óïõ, ôþñá ìðïñåßò ìÝóù ôçò óåëßäáò áõôÞò *</font>
<center><font size='4' color='Cyan'>* Ôá ÷ñÞìáôá ðïõ èá óõãêåíôñùèïýí óôïí ëïãáñéáóìü èá äéáôåèïýí ãéá öéëáíèñùðéêïýò óêïðïýò *</font>
<center><font size='4' color='Cyan'>* Alpha Bank: 704-00-2310016553 *</font>
<p>

<center><table border='1' cellspacing='1' width='90%' id='AutoNumber1' bordercolor='Yellow' style='border-style: solid; border-width: 5' background='pics/blue.jpg'>
<tr>
<td align=center bordercolor='#ffcc00'> <font face='Com' size='5' color='Lightgreen'>Ðþò óå ëÝíå?</font></td>
<td align=center bordercolor='#ffcc00'> <input type="text" name="onoma"></td>
</tr>
<tr>
<td align=center bordercolor='#ffcc00'> <font face='Com' size='5' color='Lightgreen'>Ðïéü åßíáé ôï ó÷üëéï óïõ åðß ôïõ èÝìáôïò?</font></td>
<td align=center bordercolor='#ffcc00'> <textarea name="sxolio" rows=4 cols=25 wrap="on"></textarea></td>
</tr>
<tr>
<td align=center bordercolor='#ffcc00'> <font face='Com' size='5' color='Lightgreen'>Ðïéü åßíáé ôï e-mail óïõ?</font></td>
<td align=center bordercolor='#ffcc00'> <input type="text" name="email"></td>
</tr>
<tr>
<td align=center bordercolor='#ffcc00'> <input type="submit" name="show" value="ÅìöÜíéóç"></td>
<td align=center bordercolor='#ffcc00'> <input type="submit" name="send" value="ÁðïóôïëÞ"></td>
</tr>
</table>
</form>

<br><center><font size='4' color='White'><? echo $file_diary[rand(0, count($file_diary)-1)]; ?></font></center><br><br>
<center><font size='4' color='Orange'><? echo $xronos; ?></font></center>
<center><font size='4' color='Pink'><? echo $host; ?></font></center>

<?
mysql_query("UPDATE visitor SET counter=counter+1");
$sql = mysql_query("SELECT counter FROM visitor");
$counter = mysql_fetch_array($sql);

echo "<center><font size='5' color='Yellow'>$counter[0]</font>";
echo "<center><a href='progs.php'><img src='pics/email.gif'></a>";

mail ("nik0s@mycosmos.gr", "Åðßóêåøç áðü $host! Óýíïëï: $counter[0]", "", "From: spy@web.gr");
?>

pls keep in mind the way i syntax it!

thank you very much!
u helpes a great deal!!

Posted: Wed Feb 05, 2003 2:51 pm
by Nik
Volka pls man dont leave me on this one! yous js is fine! but i have to re-arrange it a bit in order to llok like http://www.nikolas.tk but i dont know js, so pls do tour magic eith this, pls its an emergency!

Posted: Wed Feb 05, 2003 3:51 pm
by volka
you may try

Code: Select all

<?php
...
$file_data = file("data.txt");
$file_diary = file("diary.txt");
?> 
<head>
	<script type="text/javascript">
      var textToShow = "<?php echo addslashes(join('', $file_data)); ?>";
      var pos = 0;
      var tm;
      
      function init()
      { tm = setInterval("type()", 200); }
      
      function type()
      {
         if (textToShow.length != pos)
         {
            d = document.getElementById("textbox");
            d.appendChild(document.createTextNode(textToShow.charAt(pos++)));
         }
         else
            clearInterval(tm);
      }
   </script>
</head>
<body bgproperties='fixed' background='pics/anemos.bmp' onLoad="init();"> 
...

<center>
	<table border='1' cellspacing='1' width='90%' id='AutoNumber1' bordercolor='Yellow' style='border-style: solid; border-width: 5' background='pics/brick.jpg'>
		<tr>
			<td id="textbox" align="center" 
					style="color: lightblue; border-color: #ffcc00;
							font-size: small; font-family: 'Com,Times New Roman',Times,serif';" >
			</td>
		</tr>
</table> 
...
but keep the old script, haven't tested this and no time right now ;)

Posted: Wed Feb 05, 2003 4:41 pm
by Nik
<?php
error_reporting(E_ALL); $xronos=date("l dS of F h:i:s A"); $host=gethostbyaddr($_SERVER['REMOTE_ADDR']); $i=0;

if (@mysql_connect('localhost', 'nik', 'macgyver'));
else @mysql_connect('localhost', 'root');
mysql_select_db('db_nik');

if ($host=="komodino.itc.auth.gr") echo "ÂñÝ êáëþò ôïí ×ñÞóôï! ×áßñïìáé ðïõ óå âëÝðù ðÜëé! Óáí ôï óðßôé óïõ!<p>";

$file_data = file("data.txt");
$file_diary = file("diary.txt");
?>

<script type="text/javascript">
var textToShow = "<? echo addslashes(join('', $file_data)); ?>";
var pos = 0;
var tm;

function init()
{tm = setInterval("type()", 50);}

function type()
{
if (textToShow.length != pos)
{
d = document.getElementById("textbox");
d.appendChild(document.createTextNode(textToShow.charAt(pos++)));
}
else
clearInterval(tm);
}
</script>

<body bgproperties='fixed' background='pics/anemos.bmp' onLoad="init();">

<form action="show.php" method="post">
<center><font size='5' color='LightGreen'>- Ðñïò íÝïí åñùôÞóáíôá ðåñß ðñïóåõ÷Þò -</font></center><br>

<center><table border='1' cellspacing='1' width='90%' id='AutoNumber1' bordercolor='Yellow' style='border-style: solid; border-width: 5' background='pics/brick.jpg'>
<tr>
<td align=center bordercolor='#ffcc00'> <font face='Com' size='4' color='LightBlue'></font></td>
</tr>
</table>

<p>
<center><font size='4' color='Cyan'>* Áí èÝëåéò íá êÜíåéò êáé óõ ìéá äùñåÜ ðñïò óõíáíèñþðïõò ðïõ Ý÷ïõí ôçí áíÜãêç óïõ, ôþñá ìðïñåßò ìÝóù ôçò óåëßäáò áõôÞò *</font>
<center><font size='4' color='Cyan'>* Ôá ÷ñÞìáôá ðïõ èá óõãêåíôñùèïýí óôïí ëïãáñéáóìü èá äéáôåèïýí ãéá öéëáíèñùðéêïýò óêïðïýò *</font>
<center><font size='4' color='Cyan'>* Alpha Bank: 704-00-2310016553 *</font>
<p>

<center><table border='1' cellspacing='1' width='90%' id='AutoNumber1' bordercolor='Yellow' style='border-style: solid; border-width: 5' background='pics/blue.jpg'>
<tr>
<td align=center bordercolor='#ffcc00'> <font face='Com' size='5' color='Lightgreen'>Ðþò óå ëÝíå?</font></td>
<td align=center bordercolor='#ffcc00'> <input type="text" name="onoma"></td>
</tr>
<tr>
<td align=center bordercolor='#ffcc00'> <font face='Com' size='5' color='Lightgreen'>Ðïéü åßíáé ôï ó÷üëéï óïõ åðß ôïõ èÝìáôïò?</font></td>
<td align=center bordercolor='#ffcc00'> <textarea name="sxolio" rows=4 cols=25 wrap="on"></textarea></td>
</tr>
<tr>
<td align=center bordercolor='#ffcc00'> <font face='Com' size='5' color='Lightgreen'>Ðïéü åßíáé ôï e-mail óïõ?</font></td>
<td align=center bordercolor='#ffcc00'> <input type="text" name="email"></td>
</tr>
<tr>
<td align=center bordercolor='#ffcc00'> <input type="submit" name="show" value="ÅìöÜíéóç"></td>
<td align=center bordercolor='#ffcc00'> <input type="submit" name="send" value="ÁðïóôïëÞ"></td>
</tr>
</table>
</form>

<br><center><font size='4' color='White'><? echo $file_diary[rand(0, count($file_diary)-1)]; ?></font></center><br><br>
<center><font size='4' color='Orange'><? echo $xronos; ?></font></center>
<center><font size='4' color='Pink'><? echo $host; ?></font></center>

<?
mysql_query("UPDATE visitor SET counter=counter+1");
$sql = mysql_query("SELECT counter FROM visitor");
$counter = mysql_fetch_array($sql);

echo "<center><font size='5' color='Yellow'>$counter[0]</font>";
echo "<center><a href='progs.php'><img src='pics/email.gif'></a>";

mail ("nik0s@mycosmos.gr", "Åðßóêåøç áðü $host! Óýíïëï: $counter[0]", "", "From: spy@web.gr");
?>


I need to get this script working pls!

especially in the javascript part that i want it to diplay the text to data.txt char by char!! plsssss help!!

Posted: Thu Feb 06, 2003 3:16 am
by volka

Code: Select all

function init()
&#123; tm = setInterval("type()", 200); &#125;
when this function init() is called it will make type() be called once every 1/5 second. http://www.devguru.com/Technologies/ecm ... erval.html

Code: Select all

function type()
&#123;
	if (textToShow.length != pos) // if we're not already "behind" the end
	&#123;
		d = document.getElementById("divText");
		d.appendChild(document.createTextNode(textToShow.charAt(pos++)));
	&#125;
	else
	clearInterval(tm);
&#125;
a bit unrolled

Code: Select all

function type()
&#123;
	if (textToShow.length != pos)
	&#123;
		// finding a reference to the element with the id divText
		d = document.getElementById("divText");
		
		// getting the char fromthe current position in the text
		c = textToShow.charAt(pos);
		
		// making a new text-node from this char
		n = document.createTextNode(c);
		
		// appending this new text to the currently displayed text
		d.appendChild(n);
		
		// moving to the next position
		pos++;
	&#125;
	else
		clearInterval(tm); // no more text, so clear the interval
&#125;
But my example won't work as expected with multiple lines. But this does

Code: Select all

&lt;html&gt;
&lt;head&gt;
   &lt;script type="text/javascript"&gt;
   		// marking a new line with a single chr(13), so this will lead to 2 lines:
      var textToShow = "just a test"+String.fromCharCode(13)+"and a second line";
      var pos = 0;
      var tm;
      
      function init()
      &#123;
         tm = setInterval("type()", 200);
      &#125;
      
      function type()
      &#123;
         if (textToShow.length != pos)
         &#123;
            d = document.getElementById("divText");
						c = textToShow.charAt(pos++);
						// checking wether this marks a new line or not
						if (c.charCodeAt(0) != 13)
							// simple text, just append it as before
							d.appendChild(document.createTextNode(c));
						else
							// a new line, so insert a linebreak-element
							d.appendChild(document.createElement("br"));
         &#125;
         else
            clearInterval(tm);
      &#125;
   &lt;/script&gt;
&lt;/head&gt;
&lt;body onload="javascript:init();"&gt;
   &lt;div id="divText" style="border: 5px solid yellow; width: 200px; height: 50px;"&gt;
   &lt;/div&gt;
&lt;/body&gt;
Now let's dynamically create a string for js with php that is feasable for that script. You're reading the content of the file via $file_data = file("data.txt");, so you will receive an array with each line as an element. But the lines will contain the linebreak as character, not good for the script. Get rid of it.

Code: Select all

<?php $file_data = array_map('trim', $file_data); ?>
There may also be charaters in those lines that will break the script down, so they need to be escaped

Code: Select all

<?php $file_data = array_map('addslashes', $file_data); ?>
Now let's make one string from the array

Code: Select all

<?php $file_data = join('', $file_data); ?>
http://www.php.net/manual/en/function.join.php
It's one string now, but there are no linebreaks anymore.

Code: Select all

<?php $file_data = join('"+String.fromCharCode(13)+"', $file_data); ?>
This may need an example.
  • Say $file_data contains
  • just a test
  • and a second line
join will put the glue between each element so the result will be just a test"+String.fromCharCode(13)+"and a second line. If the php-script outputs it this way

Code: Select all

var textToShow = "<?php $file_data ?>";
the javascript interpreter will receive var textToShow = "just a test"+String.fromCharCode(13)+"and a second line";. Just as wanted.
Putting it all together (a bit compressed) the example now is

Code: Select all

<?php
$file_data = file("data.txt");
?>
<html><head>
<script type="text/javascript">
var textToShow = "<? echo join('"+String.fromCharCode(13)+"', array_map('addslashes', (array_map('trim', $file_data)))); ?>";
var pos = 0;
var tm;

function init()
{ tm = setInterval("type()", 50); }
	
function type()
{
	if (textToShow.length != pos)
	{
		d = document.getElementById("divText");
		c = textToShow.charAt(pos++);
		if (c.charCodeAt(0) != 13)
			d.appendChild(document.createTextNode(c));
		else
			d.appendChild(document.createElement("br"));
	}
	else
		clearInterval(tm);
}
</script>
</head>
<body onload="javascript:init();">
   <div id="divText" style="border: 5px solid yellow; width: 200px; height: 50px;">
   </div>
</body>
</html>

Posted: Thu Feb 06, 2003 3:45 am
by Nik
for ($i=0; $i<=10000000; $i++)
echo "Thank you very much Volka";

:)

The script u gave me worked great! I just also wanted to ask what changes should i make in order for it to look like this:

http://tigani.coderz.gr/~nik/test.php

This is the same thing as js but in php running on my remote web server!
but i dont know how to produce it with js!

Slow isnt it?? even if i have it with refresh 0 :)

Thanks again! i own you my friend!

Posted: Thu Feb 06, 2003 9:43 am
by volka
"404 file not found" ;)

Javascipt inside php!

Posted: Thu Feb 06, 2003 9:49 am
by Nik
<script type="text/javascript">
var textToShow = "<? echo join('"+String.fromCharCode(13)+"', array_map('addslashes', (array_map('trim', $file_data)))); ?>";
var pos = 0;
var tm;

function init()
{ tm = setInterval("type()", 40); }

function type()
{
if (textToShow.length != pos)
{
d = document.getElementById("divText");
c = textToShow.charAt(pos++);
if (c.charCodeAt(0) != 13)
d.appendChild(document.createTextNode(c));
else
d.appendChild(document.createElement("br"));
}
else
clearInterval(tm);
}
</script>

<center><font size='5' color='LightGreen'>- Προς νέον ερωτήσαντα περί προσευχής -</font></center><br>
<body background='pics/anemos.bmp' onload='javascript:init()'>
<center>
<div id="divText" align="left" style="border: 5px solid yellow; width: 900px; height: 500px;">
<font face='Com' size='4' color='LightCyan'>
</div>
</body>

In this one why cant i replace div with <table> ??

and how am i gonan do this inside the outline to use an image?

div id="divText" background="pics/brick.jpg" align="left" style="border: 5px solid yellow

Why this wont work?

as far as this: http://tigani.coderz.gr/~nik/test.php
u changer it 1 min before your post damn!!

and i dont have the source no more!!
anyway http://www.nikolas.tk
llok at this volka pls and tell me how to bacground the table!!

and opther good stuff about div

is div a javascript commnad?

Posted: Thu Feb 06, 2003 10:12 am
by volka
you can use a table (almost any element that may contain content) and you can style font settings, colors, images, ...
But you should use css for this

Code: Select all

<html>
<head>
   <script type="text/javascript">
   		// marking a new line with a single chr(13), so this will lead to 2 lines:
      var textToShow = "just a test"+String.fromCharCode(13)+"and a second line";
      var pos = 0;
      var tm;
      
      function init()
      &#123;
         tm = setInterval("type()", 100);
      &#125;
      
      function type()
      &#123;
         if (textToShow.length != pos)
         &#123;
            d = document.getElementById("divText");
						c = textToShow.charAt(pos++);
						// checking wether this marks a new line or not
						if (c.charCodeAt(0) != 13)
							// simple text, just append it as before
							d.appendChild(document.createTextNode(c));
						else
							// a new line, so insert a linebreak-element
							d.appendChild(document.createElement("br"));
         &#125;
         else
            clearInterval(tm);
      &#125;
   </script>
</head>
<body onload="javascript:init();" style="background-color: darkblue">
	<table border="1" style="background-image: url('test.png')">
		<tr>
			<td >1</td>
			<td id="divText" style="border: 5px solid yellow; width: 400px; height: 400px; color: lightblue; font-size: small; font-family: 'Com,Times New Roman',Times,serif';">
			</td>
		</tr>
		<tr><td>3</td><td>4</td></tr>
	</table>
</body>
</html>
if you do something like

Code: Select all

<div id="divText" align="left" style="border: 5px solid yellow; width: 900px; height: 500px;">
<font face='Com' size='4' color='LightCyan'>
</div>
  • it's
  • not valid html anymore (structural error)
  • useless if combined with appendChild. THe browser will treat it as

    Code: Select all

    <div ...>
       <font ...></font>
       <!-- append child will take place here, outside the font-tag -->
    </div>