|
| [Help!] Masalah dengan PHP | |
| | Pengirim | Message |
---|
LowlingLife Administrator
Posts : 2000 Thanked : 25 Engine : Multi-Engine User
Trophies
Awards:
| Subyek: [Help!] Masalah dengan PHP 2011-10-09, 08:11 | |
| Jadi gini.... Kan aku mau bikin word generator berdasarkan kode yang diberikan oleh Seventh Sanctum... Nah, aku tuh udah bikin listnya banyak banget.. Kan kalo di seventh sanctum ada pilihan berapa banyak kata yang akan di generate atau Number to Generate.... Kan aku udah kasih pilihan 1-25... Tapi tetap aja yang keluar cuma 1 kata. Mestinya kan kalo dipilih 10 maka akan keluar 10 kata..... Generatornya itu kayak aneh... Jadi nge-reset ke 1 setiap dipilih... Kayaknya ada masalah sama variable nya... Nih kodenya : - Spoiler:
- Code:
-
<html> <HEAD> <TITLE> Basic Word Generator </TITLE> </HEAD> <body> <CENTER> <B> <FONT SIZE=5>Basic Word Generator</FONT> </B> </CENTER> <?php
//Initialize srand((double)microtime()*1000000);
if ($selGenCount < 1) { $selGenCount=1; }
//Data setup $strWords = array(); $intWordCode = array(); $intFetchCode = array(); $strFetchText = array();
$objData=fopen("filedat.dat","r");
if(!($objData)) { print("File could not be opened."); exit; }
$intState=0; $bOrgLevel=false;
while (!feof($objData)) { $strLine=fgets($objData,1024);
if (strlen($strLine)>1) { if (strlen(strrpos($strLine,"\n"))>0) { $strLine=substr($strLine,0,strlen($strLine)-2); } } //First, see if there is a comment (//) line. //Then, see if it is a categorization (--) line. This changes state. //If it is neither, check the states to see what we're doing.
if (substr($strLine,0,2)=="//") { //Do nothing. } elseif ($strLine=="--ORGANIZATION") { $intState=1; $bOrgLevel=false; } elseif ($strLine=="--VOCABULARY") { $intState=2; } else { if (count(strlen($strLine))>0) { switch($intState) { case 0: //Nothing break; case 1: if ($bOrgLevel==true) { $strFetchText[count($strFetchText)] = explode(",",$strLine); $bOrgLevel=false; } else { $intFetchCode[count($intFetchCode)] = explode(",",$strLine); $bOrgLevel=true; } break; case 2: if (strlen(strpos($strLine,","))>0) { $strHolder=strtolower(chop(trim(substr($strLine, (strpos($strLine,",")+1), strlen($strLine))))); $bTrump=($strHolder=="true"); $strLine=chop(trim(substr($strLine, 0, (strpos($strLine,","))))); $strWords[count($strWords)] = $strLine; $intWordCode[count($intWordCode)] = intval($strHolder); } else { $strWords[count($strWords)] = $strLine; $intWordCode[count($intWordCode)] = 0; } break; } } } }
fclose($objData);
?> <HR> <form action="baseword.php" method="POST" name="frmControls"> <p>Number to Generate: <select name="selGenCount" size="1"> <?php if ($selGenCount==1) { print("<option value=1 selected>1</option>"); } else { print("<option value=1>1</option>"); }
for ($intLooper=5;$intLooper<55;$intLooper+=5) { if ($selGenCount==$intLooper) { print("<option value=$intLooper selected>$intLooper</option>"); } else { print("<option value=$intLooper>$intLooper</option>"); } }
?> </select> <input type="submit" name="subGenerate" value="Generate"></p> </form> <HR><?php
function GetWord($intNeedGet,$intAlreadyHave) { global $intWordCode; $bStop = false; do { if (count($intWordCode)==1) { $intReturnNumber=0; } else { $intReturnNumber=rand(0,count($intWordCode)-1); }
$bStop=true;
if (($intWordCode[$intReturnNumber] & $intNeedGet)!=$intNeedGet) { $bStop=false; }
for ($intLooper=0;$intLooper<count($intAlreadyHave);$intLooper++) { if ($intReturnNumber==$intAlreadyHave[$intLooper]) { $bStop=false; } }
} while ($bStop==false);
return($intReturnNumber); }
function GenTerm() { //Get access to the fetch array. global $intFetchCode; global $strFetchText; global $strWords;
settype($strTerm, "string");
$intLooper=0; //Only a 25% chance of a title
if ((count($intFetchCode)-1)==0) { $intWhichFetch = 0; } else { $intWhichFetch = rand(0,count($intFetchCode)-1); }
$intArrayHold=array();
for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++) { $intArrayHold[$intLooper]=-1; }
for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++) { $intArrayHold[$intLooper]=GetWord($intFetchCode[$intWhichFetch][$intLooper], $intArrayHold); }
$strTerm=$strFetchText[$intWhichFetch][0];
for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++) { $strTerm .= $strWords[$intArrayHold[$intLooper]]; $strTerm .= $strFetchText[$intWhichFetch][$intLooper+1]; }
return($strTerm); }
if ($selGenCount > 1) { print("<B>Creation:</B><BR>"); } else { print("<B>Creations:</B><BR>"); }
$aGenHold=array();
for ($intLooper=0;$intLooper<$selGenCount;$intLooper++) {
$aGenHold[$intLooper]=GenTerm(); }
sort($aGenHold);
for ($intLooper=0;$intLooper<$selGenCount;$intLooper++) { print($aGenHold[$intLooper]); print("<BR>"); }
?> <HR> </body> </html>
Nih screenshotnya yang aku kira itu problemnya Note : Perlu diingat bahwa kejadian yang nge-reset ke 1 itu tetap berlanjut walaupun sudah di-upload ke website.... Itu kodenya masih pure, belum diapa-apain... | |
| | | nasgor Senior
Posts : 711 Thanked : 3 Engine : RM2k3 Skill : Skilled Type : Writer
| Subyek: Re: [Help!] Masalah dengan PHP 2011-10-09, 13:17 | |
| - Code:
-
$strLine=fgets($objData,1024); if (strlen($strLine)>1) { if (strlen(strrpos($strLine,"\n"))>0) { $strLine=substr($strLine,0,strlen($strLine)-2); } } disinilah masalahnya.. harusnya - Code:
-
$strLine0=fgets($objData,1024); if (strlen($strLine0)>1) { if (strlen(strrpos($strLine0,"\n"))>0) { $strLine .= substr($strLine0,0,strlen($strLine0)-2); } } $strLine .= substr($strLine,0,strlen($strLine)-2);padahal km bisa pake - Code:
-
$f=file('target.dat'); foreach($f as $v) $strLine.=$v; jgn lupa gabung di https://www.facebook.com/groups/262652623756604/ | |
| | | LowlingLife Administrator
Posts : 2000 Thanked : 25 Engine : Multi-Engine User
Trophies
Awards:
| Subyek: Re: [Help!] Masalah dengan PHP 2011-10-10, 17:48 | |
| Om, itu maksudnya harus di-replace om? | |
| | | nasgor Senior
Posts : 711 Thanked : 3 Engine : RM2k3 Skill : Skilled Type : Writer
| Subyek: Re: [Help!] Masalah dengan PHP 2011-10-12, 10:15 | |
| iya donk.. ada pertanyaan lagi? | |
| | | LowlingLife Administrator
Posts : 2000 Thanked : 25 Engine : Multi-Engine User
Trophies
Awards:
| Subyek: Re: [Help!] Masalah dengan PHP 2011-10-14, 16:41 | |
| Wah, om... Yang di replace itu $strLine .= substr($strLine,0,strlen($strLine)-2); -> $f=file('target.dat'); foreach($f as $v) $strLine.=$v; doang atau $strLine=fgets($objData,1024); if (strlen($strLine)>1) { if (strlen(strrpos($strLine,"\n"))>0) { $strLine=substr($strLine,0,strlen($strLine)-2); } } -> $f=file('target.dat'); foreach($f as $v) $strLine.=$v; ? Karena saya coba gak bisa.... | |
| | | nasgor Senior
Posts : 711 Thanked : 3 Engine : RM2k3 Skill : Skilled Type : Writer
| Subyek: Re: [Help!] Masalah dengan PHP 2011-10-22, 18:27 | |
| ternyata problemnya bukan 1 tp banyak.. bahkan gw sampe harus bikin ulang - Code:
-
<html> <HEAD> <TITLE> Basic Word Generator </TITLE> </HEAD> <body> <CENTER> <B> <FONT SIZE=5>Basic Word Generator</FONT> </B> </CENTER> <?php $selGenCount =$_POST[selGenCount]; //Initialize srand((double)microtime()*1000000);
if ($selGenCount < 1) { $selGenCount=1; }
//Data setup $strWords = array(); $intWordCode = array(); $intFetchCode = array(); $strFetchText = array();
$ar=file("filedat.dat") or die("File could not be opened."); foreach($ar as $f) { $strLine=trim($f); if($strLine=="\n") continue; if ($strLine=="//") continue; if ($strLine=="--ORGANIZATION") { $intState=1; continue; } if ($strLine=="--VOCABULARY") { $intState=2; continue; } switch($intState) { case 0: //Nothing break; case 1: if ($bOrgLevel==true) { $strFetchText[ ] = explode(",",$strLine); $bOrgLevel=false; } else { $intFetchCode[ ] = explode(",",$strLine); $bOrgLevel=true; } break; case 2: if (strlen(strpos($strLine,","))>0) { $strHolder=strtolower(chop(trim(substr($strLine, (strpos($strLine,",")+1), strlen($strLine))))); $bTrump=($strHolder=="true"); $strLine=chop(trim(substr($strLine, 0, (strpos($strLine,","))))); $strWords[ ] = $strLine; $intWordCode[ ] = intval($strHolder); } else { $strWords[ ] = $strLine; $intWordCode[ ] = 0; } break; }
}
fclose($objData);
//print_r($strWords); ?> <HR> <form action="?f=12" method="POST" name="frmControls"> <p>Number to Generate: <select name="selGenCount" size="1"> <?php if ($selGenCount==1) { print("<option value=1 selected>1</option>"); } else { print("<option value=1>1</option>"); }
for ($intLooper=5;$intLooper<55;$intLooper+=5) { if ($selGenCount==$intLooper) { print("<option value=$intLooper selected>$intLooper</option>"); } else { print("<option value=$intLooper>$intLooper</option>"); } }
?> </select> <input type="submit" name="subGenerate" value="Generate"></p> </form> <HR><?php
function GetWord($intNeedGet,$intAlreadyHave) { global $intWordCode; $bStop = false; do { if (count($intWordCode)==1) { $intReturnNumber=0; } else { $intReturnNumber=rand(0,count($intWordCode)-1); }
$bStop=true;
if (($intWordCode[$intReturnNumber] & $intNeedGet)!=$intNeedGet) { $bStop=false; }
for ($intLooper=0;$intLooper<count($intAlreadyHave);$intLooper++) { if ($intReturnNumber==$intAlreadyHave[$intLooper]) { $bStop=false; } }
} while ($bStop==false);
return($intReturnNumber); }
function GenTerm() { //Get access to the fetch array. global $intFetchCode; global $strFetchText; global $strWords;
settype($strTerm, "string");
$intLooper=0; //Only a 25% chance of a title
if ((count($intFetchCode)-1)==0) { $intWhichFetch = 0; } else { $intWhichFetch = rand(0,count($intFetchCode)-1); }
$intArrayHold=array();
for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++) { $intArrayHold[$intLooper]=-1; }
for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++) { $intArrayHold[$intLooper]=GetWord($intFetchCode[$intWhichFetch][$intLooper], $intArrayHold); }
$strTerm=$strFetchText[$intWhichFetch][0];
for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++) { $strTerm .=" ". $strWords[$intArrayHold[$intLooper]]; $strTerm .=" ". $strFetchText[$intWhichFetch][$intLooper+1]; }
return($strTerm); }
if(intval($selGenCount) == 1) { print("<B>Creation:</B><BR>"); } else { print("<B>Creations:</B> <BR>"); }
$aGenHold=array();
for ($intLooper=0;$intLooper<$selGenCount;$intLooper++) { $aGenHold[$intLooper]=GenTerm(); }
sort($aGenHold);
for ($intLooper=0;$intLooper<$selGenCount;$intLooper++) { print($aGenHold[$intLooper]); print("<BR>"); }
?> <HR> </body> </html> dari masalah baca file hingga terakhir masalah dia gk pake $selGenCount =$_POST[selGenCount]; | |
| | | Sponsored content
| Subyek: Re: [Help!] Masalah dengan PHP | |
| |
| | | | [Help!] Masalah dengan PHP | |
|
Similar topics | |
|
| Permissions in this forum: | Anda tidak dapat menjawab topik
| |
| |
| Latest topics | » [Web Novel] Gloria Infidelis by LightNightKnight 2016-11-17, 21:27
» [Announcement] Forum baru untuk RMID by TheoAllen 2016-08-25, 16:39
» Where I'm Wrong ? by ReydVires 2016-07-24, 16:10
» flakeheartnet's Resources part III by flakeheartnet 2016-07-08, 14:30
» Keira's Art Warehouse by KeiraBlaze 2016-06-28, 19:27
» Theo Core Time System + Bingung by Lockin 2016-06-27, 16:24
» Error Script, Maybe ? by Lockin 2016-06-27, 16:20
» Nusaimoe @ RMID Lounge by Jihad Bagas 2016-06-21, 05:02
» Call Random Battle by Lockin 2016-06-15, 17:04
» Flakeheartnet Resources Part II [come back gift] by flakeheartnet 2016-06-07, 15:51
|
Statistics
|
Members: [ 4947 ]
Topics: [ 8258 ]
Posts: [ 112606 ]
Newest member: [ https://rmid.forumotion.net/u4968 ]
|
|
|
|