|
View:
New views
10 Messages
—
Rating Filter:
Alert me
|
|
|
Comparison Problems with 5.2.5Hi,
I have runned into a slight annoying problem with my code, that I have never had before. Either I have something wrong in my code or PHP 5.2.5 that I user is acting weird in windows. I have recently installed PHP on my windows machine for local developement instead of a remote server. What I try to do is to make an if statement betwean two string numbers. $_USER['level'] = The level the user has The $_USER['level'] string is taken from the Database and is "5". This will not work (I expect this to work since _USER['level'] is 5) if($_USER['level'] => 5) This will work (And I expect it to work to) if($_USER['level'] => 6) This will work (Not supposed to work since _USER['level'] is 5) if($_USER['level'] > 5) |
|
|
Re: Comparison Problems with 5.2.5Magnus Anderson wrote:
> > ...snip... > > This will not work (I expect this to work since _USER['level'] is 5) > if($_USER['level'] => 5) > Try if($_USER['level'] >= 5) maybe it helps ('=>' is used when assigning values in an hash, maybe you are triggering something strange...) -- Antinori and Partners - http://www.antinoriandpartners.com Soluzioni web - da professionisti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Using PHP to remove certain number of bytes from fileIs it possible with PHP to remove a certain number of bytes from a file,
purely within PHP? If so, does someone have an example of doing this, removing the first 230 bytes from a file. Thanks, Scott. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Comparison Problems with 5.2.5On Dec 30, 2007 8:04 AM, Silvio Porcellana <sporc@...> wrote:
> Magnus Anderson wrote: > > > > ...snip... > > > > This will not work (I expect this to work since _USER['level'] is 5) > > if($_USER['level'] => 5) > > > > Try > if($_USER['level'] >= 5) > > maybe it helps ('=>' is used when assigning values in an hash, maybe you > are triggering something strange...) > > -- > Antinori and Partners - http://www.antinoriandpartners.com > Soluzioni web - da professionisti > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > I think it needs to be >= (greater than or equal to) or <= (less than or equal to). -Casey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
|
|
|
Re: Using PHP to remove certain number of bytes from fileOn Sun, 2007-12-30 at 17:20 +0000, Scott Wilcox wrote:
> Is it possible with PHP to remove a certain number of bytes from a file, > purely within PHP? Yes. Why wouldn't it? > If so, does someone have an example of doing this, removing the first > 230 bytes from a file. No, that's an awfully specific problem. But here's the tools you'll need: fopen(), fread(), fwrite(), fclose(). Further info... you could do this without creating a separate temporary file (meaning shift bytes within a single file), but I suggest using a temporary target file for writing the new content, and then replacing the original once everything has completed successfully. Cheers, Rob. -- ........................................................... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ........................................................... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Fwd: Using PHP to remove certain number of bytes from fileOn Sun, 2007-12-30 at 14:14 -0500, Benjamin Darwin wrote:
> Maybe one of these days I'll remember to actually reply to the list the > first time. > > > ---------- Forwarded message ---------- > From: Benjamin Darwin <bddarwin@...> > Date: Dec 30, 2007 2:12 PM > Subject: Re: [PHP] Using PHP to remove certain number of bytes from file > To: Scott Wilcox <sc0tt@...> > > > Try this: > > $file_data = file_get_contents('filename', false, null, 230); > file_put_contents('filename', $file_data); I don't suggest this route with files that are in the hundreds of megs :) But admittedly, it's the simplest solution for small files. Also, can't use it if you're stuck with PHP 4 since it doesn't support file_put_contents(). PHP4 is dead now anyways, supposedly, so I read someplace ;) Cheers, Rob. -- ........................................................... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ........................................................... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Fwd: Using PHP to remove certain number of bytes from fileOn Dec 30, 2007 11:26 AM, Robert Cummings <robert@...> wrote:
> On Sun, 2007-12-30 at 14:14 -0500, Benjamin Darwin wrote: > > Maybe one of these days I'll remember to actually reply to the list the > > first time. > > > > > > ---------- Forwarded message ---------- > > From: Benjamin Darwin <bddarwin@...> > > Date: Dec 30, 2007 2:12 PM > > Subject: Re: [PHP] Using PHP to remove certain number of bytes from file > > To: Scott Wilcox <sc0tt@...> > > > > > > Try this: > > > > $file_data = file_get_contents('filename', false, null, 230); > > file_put_contents('filename', $file_data); > > I don't suggest this route with files that are in the hundreds of > megs :) But admittedly, it's the simplest solution for small files. > Also, can't use it if you're stuck with PHP 4 since it doesn't support > file_put_contents(). PHP4 is dead now anyways, supposedly, so I read > someplace ;) > > Cheers, > Rob. > -- > ........................................................... > SwarmBuy.com - http://www.swarmbuy.com > > Leveraging the buying power of the masses! > ........................................................... > > -- > > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > <?php $fh = fopen($file, 'rb'); $f2 = fopen('temp', 'wb'); fseek($fh, 230); do { fwrite($f2, fread($fh, 4069)); } while (!feof($fh); fclose($fh); fclose($f2); rename('temp', $file); ?> -Casey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Comparison Problems with 5.2.5You want >= and not =>
The => operator doesn't even make any sense in that context, as far as I know... On Sun, December 30, 2007 8:34 am, Magnus Anderson wrote: > > Hi, > > I have runned into a slight annoying problem with my code, that I have > never > had before. > Either I have something wrong in my code or PHP 5.2.5 that I user is > acting > weird in windows. I have recently installed PHP on my windows machine > for > local developement instead of a remote server. > > What I try to do is to make an if statement betwean two string > numbers. > > $_USER['level'] = The level the user has > > The $_USER['level'] string is taken from the Database and is "5". > > This will not work (I expect this to work since _USER['level'] is 5) > if($_USER['level'] => 5) > > This will work (And I expect it to work to) > if($_USER['level'] => 6) > > This will work (Not supposed to work since _USER['level'] is 5) > if($_USER['level'] > 5) > > -- > View this message in context: > http://www.nabble.com/Comparison-Problems-with-5.2.5-tp14547671p14547671.html > Sent from the PHP - General mailing list archive at Nabble.com. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Using PHP to remove certain number of bytes from fileOn Sun, December 30, 2007 11:20 am, Scott Wilcox wrote:
> Is it possible with PHP to remove a certain number of bytes from a > file, > purely within PHP? > > If so, does someone have an example of doing this, removing the first > 230 bytes from a file. Something like this might work: <?php $path = "/full/path/to/file"; $file = fopen($path, 'r+') or die("Could not open $path"); //read 200 bytes $goners = fread($file, 200); if (!strlen($goners) === 200){ ftruncate($file, 0); } $offset = 0; while(!feof($file)){ $buffer = fread($file, 2048); ftell($file, $offset); fwrite($file, $buffer); $offset += strlen($buffer); ftell($file, $offset + 200); } ?> -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
| Free embeddable forum powered by Nabble | Forum Help |