| | | [Help!] Masalah dengan PHP | |
| Sun 9 Oct 2011 - 8:11 |  [Help!] Masalah dengan PHP |
|---|
LowlingLife Global Moderator


 Post Count: 1296 Joined: 2011-06-28 Thanked: 21 Engine: Multi-Engine User
Awards: 
 | | 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...______________________ Training to be : A Reviewer A Writer A Journalist Epic Quote : [20:04:54] @ TheoAllen : jarang2 ada member yg nasionalis RMID bgt   Thread That I Support :  All of my script are made under this license Cause Ngacay can bring inspiration & makes you healthy!Join Ngacay Club!  |
| | | | Sun 9 Oct 2011 - 13:17 |  Re: [Help!] Masalah dengan PHP |
|---|
nasgor Senior RMer D


 Post Count: 706 Joined: 2010-09-29 Thanked: 3 Engine: RM2k3 Skill: Skilled Type: Writer
| | | 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 http://www.facebook.com/groups/262652623756604/ |
| | | | Mon 10 Oct 2011 - 17:48 |  Re: [Help!] Masalah dengan PHP |
|---|
LowlingLife Global Moderator


 Post Count: 1296 Joined: 2011-06-28 Thanked: 21 Engine: Multi-Engine User
Awards: 
 | | Om, itu maksudnya harus di-replace om? ______________________ Training to be : A Reviewer A Writer A Journalist Epic Quote : [20:04:54] @ TheoAllen : jarang2 ada member yg nasionalis RMID bgt   Thread That I Support :  All of my script are made under this license Cause Ngacay can bring inspiration & makes you healthy!Join Ngacay Club!  |
| | | | Wed 12 Oct 2011 - 10:15 |  Re: [Help!] Masalah dengan PHP |
|---|
nasgor Senior RMer D


 Post Count: 706 Joined: 2010-09-29 Thanked: 3 Engine: RM2k3 Skill: Skilled Type: Writer
| | iya donk.. ada pertanyaan lagi? |
| | | | Fri 14 Oct 2011 - 16:41 |  Re: [Help!] Masalah dengan PHP |
|---|
LowlingLife Global Moderator


 Post Count: 1296 Joined: 2011-06-28 Thanked: 21 Engine: Multi-Engine User
Awards: 
 | | 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.... ______________________ Training to be : A Reviewer A Writer A Journalist Epic Quote : [20:04:54] @ TheoAllen : jarang2 ada member yg nasionalis RMID bgt   Thread That I Support :  All of my script are made under this license Cause Ngacay can bring inspiration & makes you healthy!Join Ngacay Club!  |
| | | | Sat 22 Oct 2011 - 18:27 |  Re: [Help!] Masalah dengan PHP |
|---|
nasgor Senior RMer D


 Post Count: 706 Joined: 2010-09-29 Thanked: 3 Engine: RM2k3 Skill: Skilled Type: Writer
| | 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]; |
| | | | | | [Help!] Masalah dengan PHP | |
|
| Page 1 of 1 |
| | Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| Survey | | | Hapus Introduce Yourself? | | Ya | | 44% | [ 35 ] | | Tidak | | 56% | [ 44 ] |
| | Total Votes : 79 |
|
|
Statistics
|
Members: [ 2878 ]
Topics: [ 5389 ]
Posts: [ 83475 ]
Newest member: [ raharja ]
|
|
|
|
|
|