php-general Digest 1 May 2011 07:37:43 -0000 Issue 7291

Topics (messages 312593 through 312606):

Re: postgresql database access failure
        312593 by: Daniel Brown
        312594 by: Daniel Brown

Re: dynamic copyright in page footer?
        312595 by: Lars Nielsen
        312597 by: Andre Polykanine
        312605 by: Sharl.Jimh.Tsin
        312606 by: Walkinraven

Re: Why Constants could Not be Array?
        312596 by: Andre Polykanine
        312598 by: Stuart Dallas

Re: Wiki formatting class or something similar
        312599 by: Andre Polykanine
        312600 by: Peter Lind

Spaces in filename or path
        312601 by: Tim Streater
        312602 by: Richard Quadling
        312603 by: Tim Streater
        312604 by: Ashley Sheridan

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
    Readers?  Sounds like you spend too much time writing newsletters
(to the wrong address, since [email protected] is
a self-help command list for digest-form subscriptions).  ;-P

On Sat, Apr 30, 2011 at 04:41, e-letter <[email protected]> wrote:
>        <?php
>                $db = pg_connect('dbname=databasename user=username');
>                $query = 'SELECT * FROM databasename';
>                $value=pg_fetch_result($query,1,0);
>                echo 'export of database is ',$value,'';
>        ?>
>        <p>
>                why does this fail?

    How is it failing?  What error(s) are you seeing on screen or in
your log files?  Noting that $value would contain an array, is that
the problem?  And why are you using ending quotes in your echo?  You
should just place the semicolon immediately after $value.

>        </p>
>        </body>
> </html>
>
> The following php code produces the user agent:
>
>        <?php
>                echo '$_SERVER['HTTP_USER_AGENT']';
>        ?>

    First of all, no it doesn't.  Placed inside single quotes, it'll
not only try to return it verbatim (i.e. - the variable would be
printed to screen), but it'll also cause a parse error, as you reuse
single quotes in the variable key container.

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
On Sat, Apr 30, 2011 at 12:23, Daniel Brown <[email protected]> wrote:
>>
>>        <?php
>>                echo '$_SERVER['HTTP_USER_AGENT']';
>>        ?>
>
>    First of all, no it doesn't.  Placed inside single quotes, it'll
> not only try to return it verbatim (i.e. - the variable would be
> printed to screen), but it'll also cause a parse error, as you reuse
> single quotes in the variable key container.

    Forgot the "second of all" before hitting send.

    Second of all, what does this have to do with your PostgreSQL
problem?  Did I miss something?

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
lør, 30 04 2011 kl. 11:18 +0000, skrev [email protected]:
> Something simple like this would work 
> $date=date('Y');
> $startdate='2011';
> if($date == $startdate) {
> echo $startdate
> } else {
> Echo $startdate;
> Echo '-';
> echo  $date;
> 
> }
> Sent via BlackBerry from T-Mobile
> 
> -----Original Message-----
> From: David Mehler <[email protected]>
> Date: Sat, 30 Apr 2011 07:06:17 
> To: php-general<[email protected]>
> Subject: [PHP] dynamic copyright in page footer?
> 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:
> 
> <?php
> 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.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 
Hi there,

I have been using the following little chunk:

<?php
        $startYear = 2010;
        $curYear = date("Y");
        echo "&copy; ".$startYear.(($startYear!=$curYear)?' -
'.$curYear : ''); 
?>

Regards 
Lars Nielsen

http://www.lfweb.dk


--- End Message ---
--- Begin Message ---
Hello Dave,

echo "<p>Copyright © Dave Mehler, 2011 — ".date("Y")."</p>";

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

------------ Original message ------------
From: David Mehler <[email protected]>
To: php-general
Date created: , 2:06:17 PM
Subject: [PHP] dynamic copyright in page footer?


      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:

<?php
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.

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



--- End Message ---
--- Begin Message ---
it is very useful to me.thanks.

Best regards,
Sharl.Jimh.Tsin (From China **Obviously Taiwan INCLUDED**)



2011/4/30 Mark Kelly <[email protected]>:
> On Saturday 30 Apr 2011 at 14:28 Nathan Rixham wrote:
>
>> echo implode(",", range(2011,date("Y")));
>
> What an elegant solution! Thank you.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On 04/30/2011 07: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:

<?php
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.
From the view of copyright itself, the year in the notice means 'last modified date', NOT the current year. So I think you may set a timestamp field in your database, with last update time in it, and use the year (not current year), for your notice.

--
http://walkinraven.name

--- End Message ---
--- Begin Message ---
Hello Walkinraven,

I use serialize for that.
define("MY_CONSTANT", serialize(array("1", "2", "hello")));

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

------------ Original message ------------
From: Walkinraven <[email protected]>
To: [email protected]
Date created: , 12:51:15 PM
Subject: [PHP] Why Constants could Not be Array?


      For needing a constants=array, I have to use
'public static $a = array(...)'

instead.

Why the language could not relax the restriction of constants?

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



--- End Message ---
--- Begin Message ---
On Saturday, 30 April 2011 at 17:52, Andre Polykanine wrote:
Hello Walkinraven,
> 
> I use serialize for that.
> define("MY_CONSTANT", serialize(array("1", "2", "hello")));
> 
> -- 
> With best regards from Ukraine,
> Andre
> Skype: Francophile
> My blog: http://oire.org/menelion (mostly in Russian)
> Twitter: http://twitter.com/m_elensule
> Facebook: http://facebook.com/menelion

That's not a class constant. That type of constant is not defined until that 
line is executed (so an array is a valid value), whereas class constants are 
declared when the file is parsed.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/


> ------------ Original message ------------
> From: Walkinraven <[email protected]>
> To: [email protected]
> Date created: , 12:51:15 PM
> Subject: [PHP] Why Constants could Not be Array?
> 
> 
>  For needing a constants=array, I have to use
> 'public static $a = array(...)'
> 
> instead.
> 
> Why the language could not relax the restriction of constants?
> 
> -- 
> 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
> 


--- End Message ---
--- Begin Message ---
Hello Peter,

And what would you recommend as an Html sanitizing tool?

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

------------ Original message ------------
From: Peter Lind <[email protected]>
To: Stuart Dallas
Date created: , 4:26:41 PM
Subject: [PHP] Wiki formatting class or something similar


      On 30 April 2011 15:13, Stuart Dallas <[email protected]> wrote:
> On Friday, 29 April 2011 at 22:04, Andre Polykanine wrote:
> Hi everyone,
>> I allow my users to put some Html into their blogs. I filter it using
>> a great tool called HtmLawed and written by Dr. Santosh Patnaik (if
>> you're reading this, many thanks to you!).
>> However, I would like to give them a possibility to mark-up their text
>> in a more convenient way for beginners (such as Wiki or something
>> similar).
>> I searched through http://phpclasses.org/ but didn't find anything.
>> Could you suggest me something?
>> And one more question: maybe some of you already have a handy solution
>> to process smilies? Say, a user writes ":)" and this is replaced by an
>> image in my directory.
>> Thanks in advance!
>
> Markdown is a pretty good option for a wiki: 
> http://michelf.com/projects/php-markdown/
>
> Textile is another option (and supports tables which markdown does not): 
> http://textile.thresholdstate.com/
>

MarkItUp is a favourite plugin editor of mine - will allow you to work
with a lot of different syntaxes and users don't need to know them.

http://markitup.jaysalvat.com/home/

If you're considering sanitizing html instead of using a markup
language to convert into html, I'd read
http://blog.astrumfutura.com/2010/08/html-sanitisation-the-devils-in-the-details-and-the-vulnerabilities/
before settling on any tool to do the job. Far as I can tell, HtmLawed
isn't actually capable of sanitizing properly, according to the author
- unless it's since been updated to fix the problems mentioned in the
blog.

Regards
Peter

-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>


--- End Message ---
--- Begin Message ---
On 30 April 2011 21:26, Andre Polykanine <[email protected]> wrote:
> Hello Peter,
>
> And what would you recommend as an Html sanitizing tool?
>

I go by htmlpurifier when I need to sanitize html. I generally try to
avoid the issue though, by having users use other markup languages (I
like markdown but dislike textile). That's much faster and just as
secure - downside is that your users might not be as used to it.

Regards
Peter

-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

--- End Message ---
--- Begin Message ---
Does it matter to PHP filesystem functions if a path/to/file/name contains 
spaces? IOW, is this handled OK by design or should I replaces such spaces by 
backslash-space or would doing that present problems?

Thanks  --  tim


--- End Message ---
--- Begin Message ---
On 30 April 2011 22:07, Tim Streater <[email protected]> wrote:
> Does it matter to PHP filesystem functions if a path/to/file/name contains 
> spaces? IOW, is this handled OK by design or should I replaces such spaces by 
> backslash-space or would doing that present problems?
>
> Thanks  --  tim

On Windows, PHP will happily access files and directories with spaces...

<?php
file_put_contents('My name is Richard.txt', 'Hello Richard');"
?>

If you intend to pass the filename to a command line tool, then the
filename must be wrapped with double quotes ...

<?php
exec('tool.exe "My name is Richard.txt"');
?>

If you intend to pass the filename to a command line tool and the tool
has spaces in the name too, then you need to wrap both with quotes ...

<?php
exec('"C:\Program Files\tool.exe" "My name is Richard.txt"');
?>

If you are using a version of PHP before V5.3.0, please read
http://uk.php.net/manual/en/function.exec.php#101579. Your code would
need to be ...

<?php
exec('""C:\Program Files\tool.exe" "My name is Richard.txt""');
?>

I've added some _ to that so you can easily see the single and double
quotes ... (they aren't part of the real code, just there to show you
the quotes) ...

<?php
exec(_'_"_"_C:\Program Files\tool.exe_"_ _"_My name is Richard.txt_"_"_'_);
?>


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
On 30 Apr 2011 at 22:33, Richard Quadling <[email protected]> wrote: 

> On 30 April 2011 22:07, Tim Streater <[email protected]> wrote:
>> Does it matter to PHP filesystem functions if a path/to/file/name contains
>> spaces? IOW, is this handled OK by design or should I replaces such spaces by
>> backslash-space or would doing that present problems?
>>
>> Thanks  --  tim
>
> On Windows, PHP will happily access files and directories with spaces...

Richard,

I'll be doing this under OS X. I will be passing such paths/names to shell 
scripts too, but AIUI I can use escapeshellarg () there. As long as PHP 
filesystem functions don't have a problem then I should be OK.

Cheers  --  tim


--- End Message ---
--- Begin Message ---
"Tim Streater" <[email protected]> wrote:

>On 30 Apr 2011 at 22:33, Richard Quadling <[email protected]> wrote:
>
>> On 30 April 2011 22:07, Tim Streater <[email protected]> wrote:
>>> Does it matter to PHP filesystem functions if a path/to/file/name
>contains
>>> spaces? IOW, is this handled OK by design or should I replaces such
>spaces by
>>> backslash-space or would doing that present problems?
>>>
>>> Thanks  --  tim
>>
>> On Windows, PHP will happily access files and directories with
>spaces...
>
>Richard,
>
>I'll be doing this under OS X. I will be passing such paths/names to
>shell scripts too, but AIUI I can use escapeshellarg () there. As long
>as PHP filesystem functions don't have a problem then I should be OK.
>
>Cheers  --  tim
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

MacOS treats spaces the same as Linux. Like Richard said, you can use quotes if 
you're passing things to the shell, and also a backslash will work too. The 
only thing I would avoid if possible is spaces in paths that would reach the 
client side, i.e. in image paths, css files, etc, as I've heard historic 
browsers have trouble sometimes escaping the spaces automatically.


Thanks
Ash
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

--- End Message ---

Reply via email to