Business › Re: A Critical Analysis Of The Conspiracy Behind The Fall In Naira by paranorman(m): 9:49am On Feb 25, 2016 |
Loveslife, you're a good girl. |
Business › Re: Scrap Bdcs And Save Naira From Continued Devaluation by paranorman(m): 7:00pm On Feb 24, 2016 |
Good article bro. Can someone explain to me, simplistically, the roles of the BDCs apart from just selling to customers who wana avoid the rigours of going to the bank to get forex? You mean they JUST BUY Dollars and SELL IT again? |
Programming › Re: Need Help On This Basic Php by paranorman(op): 6:18pm On Feb 23, 2016 |
ChinenyeN: Paranorman, I would say that you did good, being a rookie. I always try to remind people that programming is about critical thinking, algorithms and problem-solving. I also always try to encourage newer programmers to focus more on their algorithm than the language features itself, because you will always learn the language features as you go along.
Looking at the code, I see you have a clear algorithm there. You know the necessary steps needed to solve your problem, and that is excellent. Now, as you learn more about PHP and its features, you will begin to see more appropriate functions or learn to write more appropriate methods to help you implement your algorithms in the future.
Don't hurt your development as a programmer by thinking of things as "long cuts" or "short cuts". In reality, there are no "short cuts" in programming. Rather, its all about how appropriate your algorithm is how you implemented it. thanks bro. dhtml self.. Hehehehe |
Programming › Re: Need Help On This Basic Php by paranorman(op): 2:06am On Feb 23, 2016 |
dhtml18: Na until i e-kill person with an e-knife on this thread before you guys know that I am not joking! bros, which kain solution you dey wait for na? rookie like me wey no understand anything?! That was why I laid the question all bear here, though it was kinda ambiguous at first; you guys pulled it through. Here is my own nonsense version of the code jare, I bet you and ChinenyeN will understand me after checking it out - it's kinda unnecessarily long jare, that was why I was looking for a 'shortcut': $file = "names.txt"; $fp = fopen($file, "r+" ; $output = ""; while (!feof($fp)) { $line = fgets($fp); $output[] = $line; } //end while loop $newOutput = ""; foreach ($output as $lineData) { $lineArray = explode(";", $lineData); $newLineArray = ""; foreach ($lineArray as $name) { $name = trim($name); $newLineArray[] = $name; } //end foreach $newOutput[] = $newLineArray; } //end for loop $textFile = ""; foreach ($newOutput as $data) { $newData = ""; foreach ($data as $txt) { if ($txt == "john" { $txt = str_replace($txt, "johnson", $txt); } //end if if ($txt == $data[sizeof($data) - 1]) { $txt = $txt."\n"; } else { $txt = $txt.";"; } $newData[] = $txt; } $textFile[] = $newData; } //end loop $updateOuput = ""; foreach ($textFile as $strng) { $finalText = implode("", $strng); $updateOuput .= $finalText; } //end if fclose($fp); $newFp = fopen($file, "w" ; fwrite($newFp, $updateOuput); fclose($newFp); //var_dump($updateOutput); |
Programming › Re: Need Help On This Basic Php by paranorman(op): 2:57pm On Feb 22, 2016 |
ChinenyeN: Replacement can easily occur in the while loop, just by adding an if condition.
<?php
while(($line = fgetcsv($file, ";" )) !== FALSE) {
// check for "alex" in $line[0], since that should be its index if(strcmp("alex", $line[0]) == 0) {
// once found, replace "alex" with "whatever you want" $line[0] = "whatever you want";
}
// put the contents into $names array $names[] = array($line[0], $line[1]);
}
// print the names in the $names array print_r($names);
// Should Give you /*** * Array ( * [0] => Array ( * [0] => john * [1] => jack * ) * [1] => Array ( * [0] => james * [1] => jill * ) * [2] => Array ( * [0] => whatever you want * [1] => wellington * ) * ) ***/ ?>
thanks for your time on this thread, you guys were really helpful. |
Programming › Re: Need Help On This Basic Php by paranorman(op): 9:08am On Feb 22, 2016 |
dhtml18: And i am still waiting. . . . invalid argument supplied on line 2.. Hehehehe |
Programming › Re: Need Help On This Basic Php by paranorman(op): 9:04am On Feb 22, 2016 |
ChinenyeN: My guy, I read his posts five times over just to make sure I understood well enough, and concluded that he may not have known the right words to use to describe his situation. From how I understand it now, he doesn't want to use functions that have the word "file" in them. I take it that he meant it literally (as in, if the function has the word "file", then he doesn't want to use it). So, I stuck with the f-type functions (they don't have the word "file" in them). Now, if he comes around and says that is not what he is looking for, then I will be at a loss. There's just no other way around this save for juju and there is no juju in computer programming. you are correct...! So, you haven't replaced the string though.. |
Programming › Re: Need Help On This Basic Php by paranorman(op): 8:58am On Feb 22, 2016 |
ChinenyeN: Truthfully, you cannot get a file's contents unless you open the file. Additionally, you cannot open a file without first loading it into memory. This part has little to nothing to do with programming, and everything to do with how computers are designed. Whenever you tell the computer that you want to use a certain file on your hard disk, the computer takes your command, locates the file and makes it available for you in RAM. Even the operating system that manages your file request is running in RAM. It's simply how computers work.
And on the programming side, it is the functions like fopen, file and file_get_contents that allow us to manage our file requests. In simple terms, that is how the implementation works. Even if you used another programming language and they had a different function called whatever, it would still make the same request to the OS as fopen, file and etc.
Now, if your only objective is to get the file contents as an array, without using any function with "file" in it, then I think I understand. That is something different altogether. It can easily be done using fopen, fgetcsv and fclose (the word "file" is not written out in these functions).
<?php
$names = []; // declare here for scope purposes
// make sure file can be accessed if(($file = fopen( "names.txt", "r" )) !== FALSE) {
// read each line in the file // you have the names delimited by semilcolon, so use that in the function while(($line = fgetcsv($file, ";" )) !== FALSE) {
// put the contents into $names array $names[] = array($line[0], $line[1]);
}
// done with the file, so we can now close it fclose($file);
}
// print the names in the $names array print_r($names);
// Should Give you /*** * Array ( * [0] => Array ( * [0] => john * [1] => jack * ) * [1] => Array ( * [0] => james * [1] => jill * ) * [2] => Array ( * [0] => alex * [1] => wellington * ) * ) ***/ ?>
boss, I not implying that you do not use the fopen, fgets, fputs, fwrite functions, what I mean is that you do not use functions with 'file' in its syntax; like readfile(), file_get_contents, file(), e.t.c. |
Programming › Re: Need Help On This Basic Php by paranorman(op): 8:52am On Feb 22, 2016 |
|
Programming › Re: Need Help On This Basic Php by paranorman(op): 1:36pm On Feb 21, 2016 |
dhtml18: ^^^I am not thinking anything on this one, you need to provide a justifiable reason why you want to do something that PHP has provided functions for. Maybe you are solving a quiz somewhere, or have got the whole thing wrong. Your approach of the matter is unconventional and a sheer waste of time, i have provided the only code i am going to. . . .am waiting for you to solve it yourself. okay bro, when using PC, post it I shall. |
Programming › Re: Need Help On This Basic Php by paranorman(op): 11:21am On Feb 21, 2016 |
dhtml18: Na you go solve your problem yourself, when you have solve it, bring the solution here. . . . . hehehehehe.. When I get on PC, I will post here. Bros, you self think am na |
Programming › Re: Need Help On This Basic Php by paranorman(op): 7:51am On Feb 21, 2016 |
ChinenyeN: For the record, a call to file_get_contents is equivalent to calling fopen, fread and fclose, and according to the PHP manual, it is similar to the file function, except that file_get_contents returns the contents as a string. So you can assign it to a variable and do any sort of string manipulation with it. file_get_contents is not an extension of file, both have different return values (file returns an array). If anything, both file_get_contents and file are wrappers for or extensions of the main file IO functions in PHP (i.e. fopen, fread, fwrite, fclose).
Anyway, if all you're looking to do string manipulation, then file_get_contents is the functionality you want to use. It will give you the file contents as a string and you can do what you want. Once you're done, call file_put_contents (which is equivalent to calling fopen, fwrite and fclose), if you need to save the changes, just as in the example provided by dhtml18. hey, boss I tink I am talking too program contextual than program literal. Okay, file pointer should return an arrray, not string. Do not use functions that has got the word 'file' innit ( like file(), readfile(), file_get_contents() e.t.c...) you feel me? So understand me bros, dhtml18, |
Programming › Re: Need Help On This Basic Php by paranorman(op): 8:39pm On Feb 20, 2016 |
dhtml18: Use a database bro, this your line of programming reasoning is not normal. If I know the aim of your task, and the objective, maybe I can help you. But as far as i am concerned, you are talking in riddles.
Even if you use fopen, and you manipulate the file, you still need to save it. What you are asking for to me does not really make sense - whether in PHP or any other language. We need to understand precisely what you are trying to achieve, maybe we can help you. . . .
THERE IS NO WAY IN ANY PROGRAMMING LANGUAGE, that you can change the content of an existing file without overwriting it to save changes. Even databases sef at some level use files to save the contents of the database - it does not use magic. sorry I got you guys mistaken.. What I am trying to archieve here is writing a code that changes your string of interest only.( a fraction of your strings without having to work on the whole strings and then modify your string of interest? You dig? for example dhtml18, the code you wrote at first only worked on that particular string. You get what I am saying? You modified the particular string("alex"  only. I think I abused the 'overwrite' word, so it got you all confused. So, instead of using the file() function or any extension of it, use fopen and its companions and work on "alex" only.. You talking dbms, i know. I could use that. But this is just one little challenge. Ain't nothing serious. Just trying to avoid the file() functions and its extensions |
Programming › Re: Need Help On This Basic Php by paranorman(op): 3:16pm On Feb 20, 2016 |
asalimpo: You read the file into memory, change its content save changes to disk - how dyu do this without overwriting the file? It's impossible. I don't need to google squat. Maybe, all you're interested in,is maintaining the time stamp on the file. So that after overwriting content, the stamp remains unchanged. okay then.. Can I get your version of the code? Don't use the file() or any extention of it to load the file itself into memory. |
Programming › Re: Need Help On This Basic Php by paranorman(op): 1:23pm On Feb 20, 2016 |
asalimpo: sorry bro but you have to overwrite the whole file to save your changes. nope bro, you don't have to. Do a google search on that and you'd see some cool things. Thing is, I am not satisfied. |
Programming › Re: Need Help On This Basic Php by paranorman(op): 11:15am On Feb 20, 2016 |
dhtml18: Analyze this. . . i know this one too bro. Done it. But's still uses an extended file() function. I am talking....: fopen while (!feof..) fgets ..i used these, but the code is unnessarily long and uses lots of manipulations and overwrites the whole file. You can do better. |
Programming › Re: Need Help On This Basic Php by paranorman(op): 10:18am On Feb 20, 2016 |
Oya na |
Programming › Need Help On This Basic Php by paranorman(op): 10:17am On Feb 20, 2016 |
Let's say I have a 'names.txt' file containing:
john;jack james;jill alex;wellington
each line contains surname and first-name delimited by a semcolon, each line is escaped by \n.
Say I want to modify 'alex', how can I do this without overwriting the whole file itself?
I want a code memory friendly, so don't use file() function. Don't overwrite the whole text file, just modify your string of interest.
Cc: dhtml18 |
Business › Re: Myths About Naira Devaluation - Nonso Obikili by paranorman(m): 8:18pm On Feb 16, 2016 |
Topeakintola: On imports you mean?
I do understand your skepticism. Japan embarked on a series of devaluation of the Yen in other to make its exports cheaper, while that policy worked, it created another problem. It led to stagnation in the domestic economy and they have not recovered after so many years. Right now, the Japanese economy is bleeding heavily and its market suffering losses in value
On the other hand, in theory, devaluation can help to stimulate the export economy, my problem is how it is managed in Nigeria. good argument. The question is: has/can anything been/be properly managed in country(by government)? We play politics with almost everything. I just tire. I don't support devaluation, no! |
Programming › Re: Need Help With This Basic Php by paranorman(m): 5:17pm On Feb 13, 2016 |
dhtml18: I dey look all these codes and fear dey catch me? na basic code be this one na, noting pro at all. Na you be baba na |
Programming › Re: Need Help With This Basic Php by paranorman(m): 9:07am On Feb 13, 2016 |
dhtml18: Oga o bros, wetin happen na? |
Programming › Re: Need Help With This Basic Php by paranorman(m): 2:11am On Feb 13, 2016*. Modified: 3:09am On Feb 13, 2016 |
//roll the die and create a session variable for it //create another '$count' session variable to manage pesistence - that is, the number //of trials till you make a right guess //main program control logic; I call him Jarvis function jarvis() { if (!isset($_SESSION["die"])) { $die = rand(1, 6); $_SESSION["die"] = $die; $_SESSION["count"] = 0; print <<<here <h1>Welcome Dude</h1> <p> A die was rolled, try to guess the value, okay? Good luck. </p> <form action = "" method = "post"> <button type = "submit"> continue </button> </form> here; } else { ultron(); } //end main logic if } //end jarvis //I love this main function, reminds me of Ultron function ultron() { $dice = $_SESSION["die"]; //$dice is just the session variable 'container' $guess = filter_input(INPUT_POST, 'guess' ) ; $count = $_SESSION["count"]; //you wouldn't want $_SESSION["count"] 'naked', would you? //print "<p>die: $dice</p>"; if ($guess == null) { print "<h1>Die rolled, make a guess - already!</h1>"; } else if ($guess > $dice) { $count++; print "<h1>Greater than, try again</h1>"; } else if ($guess < $dice) { $count++; print "<h1>Lesser than, try again</h1>"; } else if ($guess == $dice) { print "<h1>Weldone skipper, you guessed right!</h1>"; //print "<p>count: $count</p>"; if ($count > 1) { print "<div>.. but it took you $count times to get it right</div>"; } //end $count if } //end if //print "<p>$count</p>"; print <<<HERE <form action = "" method = "post"> <fieldset> <legend>Make the guess</legend> <input type = "text" name = "guess"/> <button type = "submit"> submit </button> </fieldset> </form> HERE; //keep the session variables 'alive'! $_SESSION["die"] = $dice; $_SESSION["count"] = $count; //kill 'em off if objective is accomplished if ($guess == $dice) { unset($_SESSION["count"]); unset($_SESSION["die"]); print "<p><a href = \"dieGuesser.php\">Start game again</a>, or click the submit button.</p>"; } } //end ultron //initiate jarvis jarvis(); //forgive me, Ultron and Jarvis are friends in Paranorman's world
cc: hollyfat |
Programming › Re: Need Help With This Basic Php by paranorman(m): 2:09am On Feb 13, 2016 |
hollyfat: Check very well, it's in the submit button <input type="submit" name="guess" value="Guess!"> you base a condition on a button?! I wouldn't do that though. |
Programming › Re: Need Help With This Basic Php by paranorman(m): 2:08am On Feb 13, 2016 |
tgmservice: try this guess = 0; $ die = rand(1,6); for($count = 1; $count <= 5; $count++){ if guess == 0{ echo "correct"; }break else{if count == 5{echo "game over";} without even trying it out, I know it won't work! |
|
Education › Re: Solve This Simple Maths by paranorman(m): 12:16pm On Jan 31, 2016 |
Tinkybabe: Paranorman!! Long time! You maths whiz  Compliments of the season. honestly, I admire you maths skills. That question you just solved, I hate its likes mehn.. Infact, I gotta do some 'quantifying' before solving such. How have you been? |
Education › Re: Solve This Simple Maths by paranorman(m): 11:58am On Jan 31, 2016 |
Tinkybabe: I'm sorry, just seeing the mention. Ans= 150
Let total work to be completed be X
It takes 75 men 10 hours to complete X/4 work in 90days
750 hrs x 90 = X/4 X =270,000 arbitrary unit
We have only (150- 90)days left to complete the work at 15 hours per person. If total no of people required to complete the remaining job is R Then
15R x 60 =3/4 X Note X =270,00
R = 225
Men to be added to previous is 225- 75 = 150 men
brilliant gurl! |
TV/Movies › Re: Nl Monikers Based On Movies by paranorman(m): 11:25am On Jan 25, 2016 |
*frowns* |
Programming › Re: Need Help With This Basic Php by paranorman(m): 8:31pm On Jan 22, 2016 |
hollyfat: Try this
<!DOCTYPE html> <html> <head> <title> Die </title> </head> <body> <?php session_start(); if (isset($_POST['guess'])) { //check if session is set for die
if (isset($_SESSION['die'])) { //check user answer if ($_POST['answer'] == $_SESSION['die']) { echo "<p>Thumbs up!, you guess right.</p>"; unset($_SESSION['die']); }else{ echo "<p>Incorrect Guess, please try again</p>"; } }else{ //roll the die again $die = rand(1,6); if ($_POST['answer'] == $die) { echo "<p>Thumbs up!, you guess right.</p>"; }else{ $_SESSION['die'] = $die; echo "<p>Incorrect Guess, please try again</p>"; } } } ?>
<form action="" method="post"> <label for="answer">Enter your guess</label> <input type="text" name="answer" id="answer" required /> <br> <input type="submit" name="guess" value="Guess!"> </form>
</body> </html>
oga, there is no object in the form with the name 'guess', //second line of your php code. |
Programming › Re: Why Are Nigerian Programmers So Dumb? by paranorman(m): 12:21pm On Jan 13, 2016 |
So, is it wrong learning to program in open source languages? I am a newbie, trying to perfect my skills in PHP/javascript before moving on something else. Someone should say something. |
Culture › Re: Can One Have Sex After Traditional Wedding? by paranorman(m): 7:53pm On Jan 11, 2016 |
I think so. If the family recognizes him as their inlaws and her father 'officially hands her over to him', her both wedding gives their blessings, you got eye witnesses and of course, all traditional requirements are fulfilled, you can. I am not even gonna wear western atires in my church wedding. Strictly trad. |
Nairaland General › Re: Dear Nairalanders: My Friend Wants To Borrow My Wedding Dress by paranorman(m): 10:11am On Jan 11, 2016 |
emmeyj: Is it right for me to borrow a friend my wedding dress for her own wedding too? Please I want to know what to do... nope! Nope!! Nope!!! Stand your ground dear. One should be delicate with such things jare. This is Nigeria where wickedness is the good. If it were the western world, nothing may be wrong with it. The fact that you asked about it makes it kinda wrong. It's YOUR WEDDING DRESS, don't share it with anyone. If your friend wants one, she can get/buy something cheap. |