Saturday, May 24, 2008

Create a Scrolling News Ticker in PHP

This document describes how to Create a Scrolling News Ticker in PHP. The script is compatible with both Internet Explorer and FireFox.

You can add this scrolling news ticker with your own text in your web pages.
Features:

  • Easy to embed into an HTML document;
  • Compatible with Internet Explorer and FireFox;
  • Full PHP & JavaScript: no plugin
  • Supports full HTML, including images, links and any other tags;
  • Smooth scrolling;
  • Very small script - fast to download;
  • Easy to customize;
  • Free for personal and commercial use.
FREE TO DOWNLOAD

Index.php

<html>

<body>

<table border="1" cellpadding="0" cellspacing="0" width="100%">

<tr>

<td><marquee behavior="scroll" scrollamount="3" scrolldelay="10" onMouseOver="stop()" onMouseOut="start()"><span id="scrollingtext">asd</span></marquee></td>

</tr>

</table>

<script language="javascript">

var xmlHttp


function GETTEXT()

{

te = document.getElementById("scrollingtext").innerHTML;

xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)

{

alert ("Your browser does not support AJAX!");

return;

}

var url="gettext.php";

url=url+"?te="+te;

url=url+"&sid="+Math.random();

xmlHttp.onreadystatechange=stateChanged;

xmlHttp.open("GET",url,true);

xmlHttp.send(null);

//alert("calling");

setTimeout("GETTEXT()",5000);

}

GETTEXT();

function stateChanged()

{

if (xmlHttp.readyState==4){

if(xmlHttp.responseText!=""){

document.getElementById("scrollingtext").innerHTML=xmlHttp.responseText;

}

}

}


function GetXmlHttpObject()

{

var xmlHttp=null;

try

{

// Firefox, Opera 8.0+, Safari

xmlHttp=new XMLHttpRequest();

}

catch (e)

{

// Internet Explorer

try

{

xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

}

}

return xmlHttp;

}

</script>

</body>

</html>



gettext.php
<?

$extext = $_GET["te"];

$text_file = "ticker.txt";

if(!($fp = fopen($text_file, "r"))) die ("Cannot open $counter_file.");

$list = fread($fp, filesize ($text_file));

if($extext!=$list){

echo $list;

}

fclose($fp);

?>

Create ticker.txt file
this file contains your scrolling text...

No comments: