Closed Thread Icon

Topic awaiting preservation: Something (Maybe PHP) to help me with JS (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=24910" title="Pages that link to Topic awaiting preservation: Something (Maybe PHP) to help me with JS (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Something (Maybe PHP) to help me with JS <span class="small">(Page 1 of 1)</span>\

 
Ensellitis
Bipolar (III) Inmate

From: New York, USA
Insane since: Feb 2002

posted posted 02-04-2005 07:46

I need something like a php script that will write to flat files, but I need it to create an ID that grows an incriment with each post...

This is what I have:
opttext[0]="Info Here"

I need something will raise the number 0 by 1 each time a word is send, and I need it to post to flat files...
I have my old shoutbox which I think would do the trick with a little modding, but I googled for hours today and couldn't find a way to raise the number by 1 for each post... So far all I can do is change "info here" to whatever is inputted by opttext[0]="$info"

Anyone have any ideas?



:: WWW || Contact || Deviations || ThoughtPrism ::

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 02-04-2005 08:17

uh?

Suppose you store all your posts seperated by
<----- i am the seperator ---> (Filtering your posts for that, of course),
and then you explode the string on that
Your last 'id' will be count($arrOfPosts);

So long,

->Tyberius Prime

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 02-04-2005 13:50

Ensellitis: when you write your flat file, do you open it in a or a+ mode directly, or have you open and read completely before ?
I doubt there is a function to read a string backward in a file, so you'll certainly have to open the file in a+ mode and do several fseek( ) to move the pointer backward until you find a separator and the opttext\[(\d+)\] pattern

Ensellitis
Bipolar (III) Inmate

From: New York, USA
Insane since: Feb 2002

posted posted 02-04-2005 16:53

I played around with different stuff after reading almost every little tutorial I could get my hands on, and after reading almost every doc on php.net... This was my final result...

code:
<?php
$file = 'data.txt';
$lines = explode("\n", file_get_contents($file));
foreach($lines as $num => $val)

$Option = $_POST['Option'];
$xcode = $_POST['message'];

count($arrOfPosts);

$strOut = "";

while (strlen($xcode)>300){
$part = substr($xcode,0,300);

$iPos1 = strrpos($part," ");
if ($iPos1===false) $iPos1 = 99;
if ($iPos1<8) $iPos1 = 99;

$iPos2 = strrpos($part,"[");
if ($iPos2===false) $iPos2 = 99;
if ($iPos2<11) $iPos2 = 99;

$iPos = min(14,$iPos1,$iPos2);
$part = substr($xcode,0,$iPos);
$strOut .= $part."";
$xcode = substr($xcode,$iPos);
}
$strOut .= $xcode;
$xcode = $strOut;

$xcode = str_replace("<","&lt;",$xcode);
$xcode = str_replace(">","&gt;",$xcode);

$xcode = str_replace("A","a",$xcode);
$xcode = str_replace("B","b",$xcode);
$xcode = str_replace("C","c",$xcode);
$xcode = str_replace("D","d",$xcode);
$xcode = str_replace("E","e",$xcode);
$xcode = str_replace("F","f",$xcode);
$xcode = str_replace("G","g",$xcode);
$xcode = str_replace("H","h",$xcode);
$xcode = str_replace("I","i",$xcode);
$xcode = str_replace("J","j",$xcode);
$xcode = str_replace("K","k",$xcode);
$xcode = str_replace("L","l",$xcode);
$xcode = str_replace("M","m",$xcode);
$xcode = str_replace("N","n",$xcode);
$xcode = str_replace("O","o",$xcode);
$xcode = str_replace("P","p",$xcode);
$xcode = str_replace("Q","q",$xcode);
$xcode = str_replace("R","r",$xcode);
$xcode = str_replace("S","s",$xcode);
$xcode = str_replace("T","t",$xcode);
$xcode = str_replace("U","u",$xcode);
$xcode = str_replace("V","v",$xcode);
$xcode = str_replace("W","w",$xcode);
$xcode = str_replace("X","x",$xcode);
$xcode = str_replace("Y","y",$xcode);
$xcode = str_replace("Z","z",$xcode);

$xcode = stripslashes($xcode);

$dataf = "data.txt";

$comfile = file($dataf);

if ($xcode != "") {
$df = fopen($dataf, "w+");
$xcode = stripslashes($xcode);

fwrite($df, "opttext[$num]=\"$xcode\" <!--$time-->\n");

for ($i = 0; $i < count($comfile); $i++){fwrite ($df, $comfile[$i]);}
fclose($df);
}

?>




All I really did was take my old shout box, and modded it for this use. It took me 5+ hours to finally get it. Then I was relized that the JS that is calling opttext would sort the entries alphabetic, but only of the same case, so I had to do the string replace, which solved that problem... The code is probably really sloppy, but it serves it's purpose. I think the script took me well over 8 hours to get it just right. The best part was that the data.txt that it writes worked as an include in the JS it's self, so any entry added via this script is automatically added. And it turns out that the JS will read the opttext in reverse order, so that turned out great, cause as you said POI, everything I read said you can't count flat file lines in reverse order.

Next thing I am going to teach myself is how to get the form to not submit if there are numbers being sent, but I think that will end up just being a simple javascript...



:: WWW || Contact || Deviations || ThoughtPrism ::

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 02-04-2005 17:12

wow, you're using a gigantic hammer here. At the minimum you should replace the ALL the str_replace by :

code:
$xcode = htmlentities( strtolower( $xcode ) );

And actually if use the output of the flat file to feed a JavaScript function, you could easily replace your :

code:
opttext[ 7 ] = "whateverr"

syntax by either :

code:
opttext.push( "whatever' )

or if you fear that the push() method is not supported by lame browsers and don't want to fix it yourself by creating a prototype, you could just use

code:
opttext[ opttext.length ] = "whateverr"

Oh and of course, to load the content of your flat file you could also use a passthru( ) to make a tail myFlatFile.txt -5

Hope that helps,

Ensellitis
Bipolar (III) Inmate

From: New York, USA
Insane since: Feb 2002

posted posted 02-05-2005 13:10

Is it possible to call a PHP file as a JS?

For example:
<script type="text/javascript" src="library_db.php"></script>
in exchange for
<script type="text/javascript" src="library_db.js"></script>

Right now I am running the JS in the actual page that is using the JS with an include that is loading the content of data.txt, and I always have preffered calling my scripts/css from an outside file...



And thanks poi for helping me get rid of my gigantic hammer in exchange for a q-tip, I am getting less "bugs" and faster process time now =)



:: WWW || Contact || Deviations || ThoughtPrism ::

Ensellitis
Bipolar (III) Inmate

From: New York, USA
Insane since: Feb 2002

posted posted 02-05-2005 13:20

Poi, you smart SOB, opttext.push( "whatever" ) works perfectly, you have NO idea how easy you just made my job =)



:: WWW || Contact || Deviations || ThoughtPrism ::

Ensellitis
Bipolar (III) Inmate

From: New York, USA
Insane since: Feb 2002

posted posted 02-07-2005 03:36

Ok, now here is another question...

I want to be able to show the database that is being made by the form...

Since the data file looks like this:

code:
opttext.push( "monkey" ) <!--added Feb 6, 05 (8:44.52 pm)-->
opttext.push( "another" ) <!--added Feb 6, 05 (8:21.57 pm)-->
opttext.push( "look" ) <!--added Feb 5, 05 (7:38.33 am)-->
opttext.push( "apple" ) <!--added Feb 5, 05 (7:29.02 am)-->
opttext.push( "test" ) <!--added Feb 5, 05 (7:28.46 am)-->



I want to remove the:
opttext.push( "
" ) <!--
-->

So pretty much all I have is
test added Feb 5, 05

The script I am using to call the data and print it is

code:
<?php    
$width=100; // Used for wordwrap
$filename="data.txt"; // Filename to print out to screen
if($script=fopen($filename,"r")){
echo "<pre>";

while (!feof($script)){
$buffer=fgets($script,4096);

echo wordwrap(htmlspecialchars($buffer),$width,"\n ");

}
fclose($script);
echo "</pre>";
}else
echo "Error opening $filename";
?>





Is it possible to do this?



:: WWW || Contact || Deviations || ThoughtPrism ::

Ensellitis
Bipolar (III) Inmate

From: New York, USA
Insane since: Feb 2002

posted posted 02-07-2005 05:08

NM, I should have tried before asking simply adding:

code:
$buffer=str_replace("opttext.push( \"","<font color='#ffffff'<b>",$buffer);
$buffer=str_replace("\" ) <!--","</b></font> ",$buffer);
$buffer=str_replace("-->","<br />",$buffer);


did the trick



:: WWW || Contact || Deviations || ThoughtPrism ::

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 02-07-2005 05:39

/!\ you forgot to close the opening FONT tag. Anyway, seeing the interrest you put on your site for the web standards I find weird that you use a deprecated tag and nest a useless B tag in it.

Technically wise, you could replace the 3 str_replace( ) by a single preg_replace( ) , but I'm not sure if it'd be faster.

Ensellitis
Bipolar (III) Inmate

From: New York, USA
Insane since: Feb 2002

posted posted 02-07-2005 17:18

Well, right now I am just trying to get this stuff working, then I am going to convert everything to standard, or try too. One of my scripts goes haywire when I put the XHTML declarer in the pages...



:: WWW || Contact || Deviations || ThoughtPrism ::

« BackwardsOnwards »

Show Forum Drop Down Menu