GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Stupid PHP Code Question... (https://gfy.com/showthread.php?t=1092837)

Webmaster Advertising 12-13-2012 11:41 PM

Stupid PHP Code Question...
 
Im getting this error on an old php file im trying to migrate across to a new server...

http://www.pixelsquaredesigns.com/words/

Any of the programmer types on here know whats causing it?

Here is the code...

Code:

<?php

// Text file containing words
$txt = '/home/orange/public_html/pixelsquaredesigns.com/words/list.txt';

$handle = fopen($txt, 'r');

if (!$handle) {
  die('Could not open...');
}

// set up arrays for storing words and concatenated words
$words = array();
$cwords = array();

// get the words
while (!feof($handle)) {
  // strip_newlines is not a real function - needs to be implemented
  array_push($words, strip_newlines(fgets($handle)));
}

// while we still have words
for ($i = 0; $i < count($words); $i++) {
  // get the current word
  $curword = $words[$i];
  // loop over the words
  foreach ($words as $word) {
      // if the word is the same as the current word, skip it - i.e. no CatCat
      if ($word == $curword) {
        continue;
      }
      // append the concatenated word to the array
      array_push($cwords, $curword.$word);
    }
}

foreach ($words as $var) echo $var."<br>";
foreach ($cwords as $var2) echo $var2."<br>";

?>

Thanks in advance for any assistance you can offer :)

CYF 12-13-2012 11:51 PM

Fatal error: Call to undefined function strip_newlines() in /home/orange/public_html/pixelsquaredesigns.com/words/index.php on line 19

I'm going to guess that the strip_newlines function isn't defined :)

Your code says " // strip_newlines is not a real function - needs to be implemented " so I'm guessing the function wasn't added.

borked 12-14-2012 12:38 AM

as CYF says
looks like your old server had display errors turned off in php.ini (which you should have for a production server) so you were not seeing this error.

Webmaster Advertising 12-14-2012 12:41 AM

So how would i fix it? I know it used to work on the old server with no problems :(

Webmaster Advertising 12-14-2012 01:04 AM

So ive edited some of the code (new code is in red) but its now throwing out a different error :(

http://www.pixelsquaredesigns.com/words/

Code:

<?php

// Text file containing words
$txt = '/home/orange/public_html/pixelsquaredesigns.com/words/list.txt';

$handle = fopen($txt, 'r');

if (!$handle) {
  die('Could not open...');
}

// set up arrays for storing words and concatenated words
$words = array();
$cwords = array();

// get the words
while (!feof($handle)) {
  function strip_newlines($str) {
 // common newline sequences - \r (carriage return), \n (newline or linefeed), and \r\n (carriage return-linefeed)
 $newlines = array(0 => '\r', 1 => '\n', 2 => '\r\n');
 // loop over the newline sequences, replacing them with nothing in the string
 foreach ($newlines as $nl) {
 $str = str_replace($nl, '', $str);
 }
 // return the cleaned string
 return $str;
 }


// while we still have words
for ($i = 0; $i < count($words); $i++) {
  // get the current word
  $curword = $words[$i];
  // loop over the words
  foreach ($words as $word) {
      // if the word is the same as the current word, skip it - i.e. no CatCat
      if ($word == $curword) {
        continue;
      }
      // append the concatenated word to the array
      array_push($cwords, $curword.$word);
    }
}

foreach ($words as $var) echo $var."<br>";
foreach ($cwords as $var2) echo $var2."<br>";

?>

What did I screw up? LOL

Sorry I'm definitely not fluent in .php but I'm learning slowly... Or trying to lol

cemtex 12-14-2012 02:54 AM

Code:

<?php

// Text file containing words
$txt = 'list.txt';


// function
function strip_newlines($str) {
        // common newline sequences - \r (carriage return), \n (newline or linefeed), and \r\n (carriage return-linefeed)
        $newlines = array(0 => '\r', 1 => '\n', 2 => '\r\n');
        // loop over the newline sequences, replacing them with nothing in the string
                foreach ($newlines as $nl) {
                $str = str_replace($nl, '', $str);
                }
        // return the cleaned string
        return $str;
}

$handle = fopen($txt, 'r');

if (!$handle) {
  die('Could not open...');
}

// set up arrays for storing words and concatenated words
$words = array();
$cwords = array();

// get the words
while (!feof($handle)) {
  // strip_newlines is not a real function - needs to be implemented
  array_push($words, strip_newlines(fgets($handle)));
}

// while we still have words
for ($i = 0; $i < count($words); $i++) {
// get the current word
$curword = $words[$i];
// loop over the words
        foreach ($words as $word) {
                // if the word is the same as the current word, skip it - i.e. no CatCat
                if ($word == $curword) {
                continue;
                }
        // append the concatenated word to the array
        array_push($cwords, $curword.$word);
        }
}

foreach ($words as $var) echo $var."<br>";
foreach ($cwords as $var2) echo $var2."<br>";

?>


VenusBlogger 12-14-2012 03:14 AM

Ask KILLSWITCH or the so Fucking Banned "EDGEPROD", HO HO HO.

They claim theirselves to be PHP NINJAS...

lol.. they dont have a fucking clue about coding at all.. Fucking noobs.

Emil 12-14-2012 04:19 AM

http://fiverr.com/gigs/search?query=fix+php&x=0&y=0

amphora 12-14-2012 05:38 AM

That new error, "Parse error: syntax error, unexpected $end", means you are missing a closing bracket. A right curly bracket, } needs to match up with one of the opening ones, {.

Another problem with your new code is although you have now defined a strip_newlines function, it is never actually called, plus it is being defined in a loop for no reason.

Those were the problems, cemtex's code should get you on track.

Webmaster Advertising 12-14-2012 09:34 AM

Quote:

Originally Posted by cemtex (Post 19369193)
Code:

<?php

// Text file containing words
$txt = 'list.txt';


// function
function strip_newlines($str) {
        // common newline sequences - \r (carriage return), \n (newline or linefeed), and \r\n (carriage return-linefeed)
        $newlines = array(0 => '\r', 1 => '\n', 2 => '\r\n');
        // loop over the newline sequences, replacing them with nothing in the string
                foreach ($newlines as $nl) {
                $str = str_replace($nl, '', $str);
                }
        // return the cleaned string
        return $str;
}

$handle = fopen($txt, 'r');

if (!$handle) {
  die('Could not open...');
}

// set up arrays for storing words and concatenated words
$words = array();
$cwords = array();

// get the words
while (!feof($handle)) {
  // strip_newlines is not a real function - needs to be implemented
  array_push($words, strip_newlines(fgets($handle)));
}

// while we still have words
for ($i = 0; $i < count($words); $i++) {
// get the current word
$curword = $words[$i];
// loop over the words
        foreach ($words as $word) {
                // if the word is the same as the current word, skip it - i.e. no CatCat
                if ($word == $curword) {
                continue;
                }
        // append the concatenated word to the array
        array_push($cwords, $curword.$word);
        }
}

foreach ($words as $var) echo $var."<br>";
foreach ($cwords as $var2) echo $var2."<br>";

?>


Thank you kindly, its appreciated.

Like i said, I'm learning php slowly, i knew there was an issue just couldnt 'see' what it was in my head.

So i was basically screwing up the handling of strip_newlines forcing the array in there, correct?

Vapid - BANNED FOR LIFE 12-14-2012 09:36 AM

Layer 7 firewall

Webmaster Advertising 12-14-2012 09:48 AM

Quote:

Originally Posted by amphora (Post 19369320)
That new error, "Parse error: syntax error, unexpected $end", means you are missing a closing bracket. A right curly bracket, } needs to match up with one of the opening ones, {.

Another problem with your new code is although you have now defined a strip_newlines function, it is never actually called, plus it is being defined in a loop for no reason.

Those were the problems, cemtex's code should get you on track.

Thank you for the explanation :)

Killswitch 12-14-2012 10:26 AM

Quote:

Originally Posted by VenusBlogger (Post 19369206)
Ask KILLSWITCH or the so Fucking Banned "EDGEPROD", HO HO HO.

They claim theirselves to be PHP NINJAS...

lol.. they dont have a fucking clue about coding at all.. Fucking noobs.

http://i.imgur.com/IHi6t.jpg

VenusBlogger 12-14-2012 05:22 PM

HAHA, funny that KILLSWITCH thinks I was referring to GFY...

Im laughing my ass off...

DOMINICO is definitely banned from that place, I had one of my friends member of the forum check on it. :)

Same as I have him gathering all the posts I cannot read, every single day... So I stay up to date and I know exactly what you post and that someone opened a thread...

Don't worry, Im always watching. :)

Take it with Lube.

Killswitch 12-14-2012 05:35 PM

Quote:

Originally Posted by VenusBlogger (Post 19370615)
HAHA, funny that KILLSWITCH thinks I was referring to GFY...

Im laughing my ass off...

DOMINICO is definitely banned from that place, I had one of my friends member of the forum check on it. :)

Same as I have him gathering all the posts I cannot read, every single day... So I stay up to date and I know exactly what you post and that someone opened a thread...

Don't worry, Im always watching. :)

Take it with Lube.

Your rat is filling you with bullshit.

VenusBlogger 12-14-2012 05:47 PM

Cada vez que busco tu nombre en google, me rio a carcajadas...

Reputation destroyed. :)

y el proximo afectado sera edgeprod, el sicko de conectivut... hihihi...

yup, saw him banned yesterday on that other place..

dont worry, I dont follow ur game.

edgeprod 12-14-2012 05:59 PM

Quote:

Originally Posted by Killswitch (Post 19370657)
Your rat is filling you with bullshit.

I'm laughing my balls off, because whoever is feeding him bad info, he probably thinks they're friends ... and the whole time .. oh, god I have tears in my eyes, I'm laughing so hard. Totally worth it. :1orglaugh

Killswitch 12-14-2012 06:07 PM

Quote:

Originally Posted by edgeprod (Post 19370726)
I'm laughing my balls off, because whoever is feeding him bad info, he probably thinks they're friends ... and the whole time .. oh, god I have tears in my eyes, I'm laughing so hard. Totally worth it. :1orglaugh

:1orglaugh:1orglaugh:1orglaugh

edgeprod 12-14-2012 07:26 PM

You know, something just occurred to me: if he WAS having access to that forum, he'd see me posting on it every day, so ... I guess he got caught in a lie either way. Ah well, it's not like he had credibility. GFY sure is nice without seeing his posts, using your ignore tool .. but if you keep QUOTING him, we still have to see THAT stuff, lol.

Killswitch 12-14-2012 07:41 PM

Quote:

Originally Posted by edgeprod (Post 19370899)
You know, something just occurred to me: if he WAS having access to that forum, he'd see me posting on it every day, so ... I guess he got caught in a lie either way. Ah well, it's not like he had credibility. GFY sure is nice without seeing his posts, using your ignore tool .. but if you keep QUOTING him, we still have to see THAT stuff, lol.

My good your bad. How's it working on your fourth computer since it RUINED your first THREE computers? :1orglaugh

edgeprod 12-14-2012 07:58 PM

Quote:

Originally Posted by Killswitch (Post 19370918)
My good your bad. How's it working on your fourth computer since it RUINED your first THREE computers? :1orglaugh

My first 43 computers. I just kept trying, and your damn script just kept RUINING computers. I had to actually throw them all out afterward. If I weren't in a third world country running a 486 DX, I'd ask you to replace at least one of them with a smoke signal station or a messenger pigeon, KILL-SWITCH.

Also: I HAVE REPORTED YOU TO THE FBI TEAM, THE GOOGLES, GIT-HUBBLE, AND FACE-BOOKING (where you have only 6 likes, how can you call yourself a WEBMATADOR)?

Killswitch 12-14-2012 08:19 PM

Quote:

Originally Posted by edgeprod (Post 19370936)
My first 43 computers. I just kept trying, and your damn script just kept RUINING computers. I had to actually throw them all out afterward. If I weren't in a third world country running a 486 DX, I'd ask you to replace at least one of them with a smoke signal station or a messenger pigeon, KILL-SWITCH.

Also: I HAVE REPORTED YOU TO THE FBI TEAM, THE GOOGLES, GIT-HUBBLE, AND FACE-BOOKING (where you have only 6 likes, how can you call yourself a WEBMATADOR)?

Just for this post I have banned you from GFY. Enjoy your SO FUCKING BANNED status, EDGE-PROD! :mad:

edgeprod 12-14-2012 08:31 PM

Quote:

Originally Posted by Killswitch (Post 19370958)
Just for this post I have banned you from GFY. Enjoy your SO FUCKING BANNED status, EDGE-PROD! :mad:

You FATTY, I will call you a KICK-BOXER now.

Killswitch 12-14-2012 08:49 PM

Quote:

Originally Posted by edgeprod (Post 19370971)
You FATTY, I will call you a KICK-BOXER now.

You can't respond to this because you're SO FUCKING BANNED! :mad:

Webmaster Advertising 12-14-2012 09:25 PM

So this is doing what it is supposed to now but i had one more question, and im not sure if its possible or not from what ive been reading, i can replace the string for a blank space however, i also read it only works for white space at the beginning or end of a word.

Is there any way i can have this script output a list like this....

onetwo
onethree
twoone
twothree

Instead of like this how it currently does...

one two
one three
two one
two three

If so, what would i put in the code and where would i put it?

Thanks for all the assistance so far :)

edgeprod 12-14-2012 09:26 PM

Quote:

Originally Posted by Killswitch (Post 19371001)
You can't respond to this because you're SO FUCKING BANNED! :mad:

I forgot. :thumbsup

Killswitch 12-14-2012 09:40 PM

Quote:

Originally Posted by Webmaster Advertising (Post 19371062)
So this is doing what it is supposed to now but i had one more question, and im not sure if its possible or not from what ive been reading, i can replace the string for a blank space however, i also read it only works for white space at the beginning or end of a word.

Is there any way i can have this script output a list like this....

onetwo
onethree
twoone
twothree

Instead of like this how it currently does...

one two
one three
two one
two three

If so, what would i put in the code and where would i put it?

Thanks for all the assistance so far :)

str_replace(' ', '', $var);

Webmaster Advertising 12-14-2012 09:45 PM

Ah, it was the $var I was missing... Thank you kindly Sir :)

Webmaster Advertising 12-14-2012 10:03 PM

Im still screwing something up :(

http://www.pixelsquaredesigns.com/words/

Has a bunch of spaces between the words, except for the last 4 lines now :/

sarettah 12-14-2012 10:22 PM

Quote:

Originally Posted by Webmaster Advertising (Post 19371138)
Im still screwing something up :(

http://www.pixelsquaredesigns.com/words/

Has a bunch of spaces between the words, except for the last 4 lines now :/

You have something other than a space in there.

So, instead of just doing the replace do a trim when you put the words together.

Here:

array_push($cwords, $curword . $word);

Change to

array_push($cwords, trim($curword) . trim($word));

or

Here:

array_push($words, strip_newlines(fgets($handle)));

change to

array_push($words, trim(strip_newlines(fgets($handle))));

Trim takes white space (not just blanks) from the beginning and end of the string.

Edited in:

A better place for it is in the strip_newlines function actually.

Changing return $str; to return trim($str); will accomplish the exact same thing with slightly less typing. It depends on how you would interpret what you want the strip_newlines function to be as to whether it is in the right place.

sarettah 12-14-2012 10:37 PM

Looking at it, I don't like the strip_newlines function in there either...lol.

I always use chr(13) and chr(10) for my new line indicators and it never fails.

So, on the read (the fget) you can do a replace of all of it and get rid of the function.

changing the read to:

array_push($words, str_replace(chr(13),'',str_replace(chr(10), '', fgets($handle))));

and getting rid of the function should take care of it nicely. If you also want rid of spaces and such (just in case) then:

array_push($words, trim(str_replace(chr(13),'',str_replace(chr(10), '', fgets($handle)))));

Should take care of it.

Webmaster Advertising 12-14-2012 10:42 PM

Quote:

Originally Posted by sarettah (Post 19371163)
You have something other than a space in there.

So, instead of just doing the replace do a trim when you put the words together.

Here:

array_push($cwords, $curword . $word);

Change to

array_push($cwords, trim($curword) . trim($word));

or

Here:

array_push($words, strip_newlines(fgets($handle)));

change to

array_push($words, trim(strip_newlines(fgets($handle))));

Trim takes white space (not just blanks) from the beginning and end of the string.

Edited in:

A better place for it is in the strip_newlines function actually.

Changing return $str; to return trim($str); will accomplish the exact same thing with slightly less typing. It depends on how you would interpret what you want the strip_newlines function to be as to whether it is in the right place.

Trim worked perfectly, thanks Sarettah.

Stupid question though, if this was just a list of words typed in notepad, one word per line, how come there was a space in there, is that an issue with the server parsing the array or something notepad related?

sarettah 12-14-2012 10:49 PM

Quote:

Originally Posted by Webmaster Advertising (Post 19371178)
Trim worked perfectly, thanks Sarettah.

Stupid question though, if this was just a list of words typed in notepad, one word per line, how come there was a space in there, is that an issue with the server parsing the array or something notepad related?

There was no space.

Your strip_newlines function is NOT stripping properly. I just did a couple of tests just to prove it to myself. There was still a carriage return and linefeed in there.

Too loopy right now to look through the function. I say get rid of it because it is unneeded.

If you go back to the code before the trim and look at view source you will see that what in html looked like a space was actual a skip down a line. But since html does not use carriage returns (it uses the <br> tag) you do not see it in the browser.

Handling the carriage return/line feeds using the chr (character function) takes care of it.

sarettah 12-14-2012 11:06 PM

Ok, the issue in the strip_newlines.

The function as shown above is using single ticks (apostrophes) for the variables:

newlines = array(0 => '\r', 1 => '\n', 2 => '\r\n');

Those need to be in double tics (quotes):

newlines = array(0 => "\r", 1 => "\n", 2 => "\r\n");

Then, it will work. But there is a condition that will NEVER get hit. The third "\r\n" will never be encountered so it can be left out and you could use

newlines = array(0 => "\r", 1 => "\n");

That would work properly and give the proper result.



.

Webmaster Advertising 12-14-2012 11:13 PM

Okay cool ill have a play with this again in the morning then, time to get mah drink on right now, thank you again for the help :)

VenusBlogger 12-15-2012 03:20 AM

Quote:

Originally Posted by edgeprod (Post 19371063)
I forgot. :thumbsup

EDGE-PROOF why is your profile in GAY DATING Sites along with your wikipidia pic ? :1orglaugh

I didn't know you were a homo.

And something tells me that IF I keep searching, I can also find KILLSWITCH profil too...

Right JOSHUA TREE ? :action-sm

KARMA is a bitch!

Killswitch 12-15-2012 09:07 AM

:1orglaugh

edgeprod 12-15-2012 11:28 AM

Well, signing us up for gay dating profiles is hil-fucking-arious and all, but it's nice to see him banned, too.

Killswitch 12-15-2012 09:54 PM

Damn, I've been out all day helping my buddy buy an engagement ring... What did I miss? What caused him to be banned?


All times are GMT -7. The time now is 05:32 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc