php-general Digest 18 Apr 2013 07:06:38 -0000 Issue 8199

Topics (messages 320863 through 320878):

Re: self operator within a double quoted string
        320863 by: Matijn Woudt
        320864 by: Marco Behnke
        320865 by: NaMarPi
        320868 by: Matijn Woudt
        320869 by: Matijn Woudt

Need a tool to minimize HTML before storing in memecache
        320866 by: Daevid Vincent
        320867 by: Joseph Moniz
        320870 by: Matijn Woudt
        320871 by: David OBrien
        320872 by: Daevid Vincent

<?=$var?>
        320873 by: Larry Martell
        320874 by: Micky Hulse
        320875 by: Micky Hulse
        320876 by: Daevid Vincent
        320877 by: Micky Hulse

[ask] convert unknown Korean's string to readable string
        320878 by: Morning Star

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Wed, Apr 17, 2013 at 7:47 PM, NaMarPi <nama...@yahoo.com> wrote:

> I would like to use self and static operators inside a double quoted
> string,
> but do not find the way to accomplish that. Could you give me a right
> direction?
>
>
> http://3v4l.org/NDkdA
>
>
> class Foo {
>
>     public static $class_prop = 'Class_Property';
>     public $object_prop = 'Object_Property';
>
>     static function printClassProp() {
>         print 'prefix_' . self::$class_prop . '_postfix' . PHP_EOL;
>         print "prefix_{\\self::$class_prop}_postfix" . PHP_EOL;       //
> <-- issue here
>     }
>
>     function printObjectProp() {
>         print "prefix_{$this->object_prop}_postfix" . PHP_EOL;
>     }
> }
>
>
> $foo = new Foo;
> $foo->printObjectProp();
>
>
> Foo::printClassProp();
>
>
Hi,

This is a bug/feature in php and is just not possible. Either use the
syntax you've used on the single quotes, or store the variable in a
temporary var before using the print.

- Matijn

--- End Message ---
--- Begin Message ---
Am 17.04.13 20:59, schrieb Matijn Woudt:
> On Wed, Apr 17, 2013 at 7:47 PM, NaMarPi <nama...@yahoo.com> wrote:
>
>> I would like to use self and static operators inside a double quoted
>> string,
>> but do not find the way to accomplish that. Could you give me a right
>> direction?
>>
>>
>> http://3v4l.org/NDkdA
>>
>>
>> class Foo {
>>
>>     public static $class_prop = 'Class_Property';
>>     public $object_prop = 'Object_Property';
>>
>>     static function printClassProp() {
>>         print 'prefix_' . self::$class_prop . '_postfix' . PHP_EOL;
>>         print "prefix_{\\self::$class_prop}_postfix" . PHP_EOL;       //
>> <-- issue here
>>     }
>>
>>     function printObjectProp() {
>>         print "prefix_{$this->object_prop}_postfix" . PHP_EOL;
>>     }
>> }
>>
>>
>> $foo = new Foo;
>> $foo->printObjectProp();
>>
>>
>> Foo::printClassProp();
>>
>>
> Hi,
>
> This is a bug/feature in php and is just not possible. Either use the
> syntax you've used on the single quotes, or store the variable in a
> temporary var before using the print.
Or use printf which is much more readable.
>
> - Matijn
>


-- 
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz


Attachment: signature.asc
Description: OpenPGP digital signature


--- End Message ---
--- Begin Message ---
I found that double quoted strings are more elegant in some situations
than single ones, and I like identical solutions for identical problems,
so that's why I asked this question.

But finally found a reason why use single quoted strings instead of double:
because the number of generated opcodes is less in the former case.

Here is a detailed explanation (the url does not exist anymore,
so make a search on the url and load the cashed version of the page):

blog.golemon.com/2006/06/how-long-is-piece-of-string.html

If anyone can run the vld package and share the currently relevant
opcodes, it will be appreciated.



>> On Wed, Apr 17, 2013 at 7:47 PM, NaMarPi <nama...@yahoo.com> wrote:
>>
>>> I would like to use self and static operators inside a double quoted
>>> string,
>>> but do not find the way to accomplish that. Could you give me a right
>>> direction?
>>>
>>>
>>> http://3v4l.org/NDkdA
>>>
>>>
>>> class Foo {
>>>
>>>     public static $class_prop = 'Class_Property';
>>>     public $object_prop = 'Object_Property';
>>>
>>>     static function printClassProp() {
>>>         print 'prefix_' . self::$class_prop . '_postfix' . PHP_EOL;
>>>         print "prefix_{\\self::$class_prop}_postfix" . PHP_EOL;       //
>>> <-- issue here
>>>     }
>>>
>>>     function printObjectProp() {
>>>         print "prefix_{$this->object_prop}_postfix" . PHP_EOL;
>>>     }
>>> }
>>>
>>>
>>> $foo = new Foo;
>>> $foo->printObjectProp();
>>>
>>>
>>> Foo::printClassProp();
>>>
>>>
>> Hi,
>>
>> This is a bug/feature in php and is just not possible. Either use the
>> syntax you've used on the single quotes, or store the variable in a
>> temporary var before using the print.
>Or use printf which is much more readable.
>>
>> - Matijn
>>
>
>
>-- 
>Marco Behnke
>Dipl. Informatiker (FH), SAE Audio Engineer Diploma
>Zend Certified Engineer PHP 5.3
>
>Tel.: 0174 / 9722336
>e-Mail: ma...@behnke.biz
>
>Softwaretechnik Behnke
>Heinrich-Heine-Str. 7D
>21218 Seevetal
>
>http://www.behnke.biz
>
>
>
>Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc

--- End Message ---
--- Begin Message ---
On Wed, Apr 17, 2013 at 10:19 PM, Marco Behnke <ma...@behnke.biz> wrote:

> Or use printf which is much more readable.
>

Are you serious about this? How would printf make things more readable?
Given a string with some %s %d etc in it, and then at the end you're giving
the stuff that replaces them. I fail to see how that improves readability
when you can put the variables in the string at exactly the place they are
printed, so the final string can be read as a somewhat normal text.

--- End Message ---
--- Begin Message ---
On Wed, Apr 17, 2013 at 11:30 PM, NaMarPi <nama...@yahoo.com> wrote:

> I found that double quoted strings are more elegant in some situations
> than single ones, and I like identical solutions for identical problems,
> so that's why I asked this question.
>
> But finally found a reason why use single quoted strings instead of double:
> because the number of generated opcodes is less in the former case.
>
> Here is a detailed explanation (the url does not exist anymore,
> so make a search on the url and load the cashed version of the page):
>
> blog.golemon.com/2006/06/how-long-is-piece-of-string.html
>
> If anyone can run the vld package and share the currently relevant
> opcodes, it will be appreciated.
>
>
 First of all, I find the url is working fine for me. While it clearly
shows that there are more opcodes generated for a specific method, it does
not show performance difference. These opcodes are virtual opcodes, that
are to be translated by the engine, and there is no guarantee that each
opcode required the same amount of cpu cycles to process, and it could
perfectly be that the instruction with the most opcodes generated is
actually the fastest of all. A real comparison would benchmark this by cpu
cycles instead of number of opcodes.

- Matijn

--- End Message ---
--- Begin Message ---
We do a lot with caching and storing in memecached as well as local copies
so as to not hit the cache pool over the network and we have found some
great tools to minimize our javascript and our css, and now we'd like to
compress our HTML in these cache slabs.

 

Anyone know of a good tool or even regex magic that I can call from PHP to
compress/minimize the giant string web page before I store it in the cache?

 

It's not quite as simple as stripping white space b/c obviously there are
spaces between attributes in tags that need to be preserved, but also in the
words/text on the page. I could strip out newlines I suppose, but then do I
run into any issues in other ways? In any event, it seems like someone would
have solved this by now before I go re-inventing the wheel.

 

d.


--- End Message ---
--- Begin Message ---
http://php.net/manual/en/book.tidy.php

- Joseph Moniz
(510) 509-0775 | @josephmoniz <https://twitter.com/josephmoniz> |
GitHub<https://github.com/JosephMoniz> |
 LinkedIn <http://www.linkedin.com/pub/joseph-moniz/13/949/b54/> |
Blog<http://josephmoniz.github.io/>
 | CoderWall <https://coderwall.com/josephmoniz>

"Wake up early, Stay up late, Change the world"


On Wed, Apr 17, 2013 at 2:52 PM, Daevid Vincent <dae...@daevid.com> wrote:

> We do a lot with caching and storing in memecached as well as local copies
> so as to not hit the cache pool over the network and we have found some
> great tools to minimize our javascript and our css, and now we'd like to
> compress our HTML in these cache slabs.
>
>
>
> Anyone know of a good tool or even regex magic that I can call from PHP to
> compress/minimize the giant string web page before I store it in the cache?
>
>
>
> It's not quite as simple as stripping white space b/c obviously there are
> spaces between attributes in tags that need to be preserved, but also in
> the
> words/text on the page. I could strip out newlines I suppose, but then do I
> run into any issues in other ways? In any event, it seems like someone
> would
> have solved this by now before I go re-inventing the wheel.
>
>
>
> d.
>
>

--- End Message ---
--- Begin Message ---
On Wed, Apr 17, 2013 at 11:52 PM, Daevid Vincent <dae...@daevid.com> wrote:

> We do a lot with caching and storing in memecached as well as local copies
> so as to not hit the cache pool over the network and we have found some
> great tools to minimize our javascript and our css, and now we'd like to
> compress our HTML in these cache slabs.
>
>
>
> Anyone know of a good tool or even regex magic that I can call from PHP to
> compress/minimize the giant string web page before I store it in the cache?
>
>
>
> It's not quite as simple as stripping white space b/c obviously there are
> spaces between attributes in tags that need to be preserved, but also in
> the
> words/text on the page. I could strip out newlines I suppose, but then do I
> run into any issues in other ways? In any event, it seems like someone
> would
> have solved this by now before I go re-inventing the wheel.
>
>
>
> d.
>
>
How about you just compress it? Gzip, bzip2, etc. Pick your favourite.
http://www.php.net/manual/en/refs.compression.php

- Matijn

--- End Message ---
--- Begin Message ---
On Wed, Apr 17, 2013 at 5:52 PM, Daevid Vincent <dae...@daevid.com> wrote:

> We do a lot with caching and storing in memecached as well as local copies
> so as to not hit the cache pool over the network and we have found some
> great tools to minimize our javascript and our css, and now we'd like to
> compress our HTML in these cache slabs.
>
>
>
> Anyone know of a good tool or even regex magic that I can call from PHP to
> compress/minimize the giant string web page before I store it in the cache?
>
>
>
> It's not quite as simple as stripping white space b/c obviously there are
> spaces between attributes in tags that need to be preserved, but also in
> the
> words/text on the page. I could strip out newlines I suppose, but then do I
> run into any issues in other ways? In any event, it seems like someone
> would
> have solved this by now before I go re-inventing the wheel.
>
>
>
> d.
>
>
I used this a while ago to do what you are asking... I modified it to my
needs

https://github.com/stevenvachon/html-minify/

--- End Message ---
--- Begin Message ---

> -----Original Message-----
> From: Matijn Woudt [mailto:tijn...@gmail.com]
> Sent: Wednesday, April 17, 2013 3:11 PM
> To: Daevid Vincent
> Cc: PHP List
> Subject: Re: [PHP] Need a tool to minimize HTML before storing in
> memecache
> 
> On Wed, Apr 17, 2013 at 11:52 PM, Daevid Vincent <dae...@daevid.com>
> wrote:
> 
> > We do a lot with caching and storing in memecached as well as local
> > copies so as to not hit the cache pool over the network and we have
> > found some great tools to minimize our javascript and our css, and now
> > we'd like to compress our HTML in these cache slabs.
> >
> >
> >
> > Anyone know of a good tool or even regex magic that I can call from
> > PHP to compress/minimize the giant string web page before I store it in the
> cache?
> >
> >
> >
> > It's not quite as simple as stripping white space b/c obviously there
> > are spaces between attributes in tags that need to be preserved, but
> > also in the words/text on the page. I could strip out newlines I
> > suppose, but then do I run into any issues in other ways? In any
> > event, it seems like someone would have solved this by now before I go
> > re-inventing the wheel.
> >
> >
> >
> > d.
> >
> >
> How about you just compress it? Gzip, bzip2, etc. Pick your favourite.
> http://www.php.net/manual/en/refs.compression.php
> 
> - Matijn

Well we already use the gzip compression that is built into Apache since that 
works in tandem with the client too. 
http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/

The point of minification is to remove comments, commented sections, optimize 
the code by removing closing tags when not needed (</p> or <br/>), strip 
unnecessary white space, etc.. there is more to it than just squeezing bits 
which is what LZO or GZIP do. They work in conjunction with each other.


--- End Message ---
--- Begin Message ---
Continuing in my effort to port an app from PHP version 5.1.6 to
5.3.3, the app uses this construct all over the place when building
links:

<?=$var?>

I never could find any documentation for this, but I assumed it was
some conditional thing - use $var if it's defined, otherwise use
nothing. In 5.1.6 it seems to do just that. But in 5.3.3 I'm not
getting the value of $var even when it is defined. Has this construct
been deprecated? Is there now some other way to achieve this?

--- End Message ---
--- Begin Message ---
It should still work. You might need to turn on the short tag option
in your conf file.

<http://stackoverflow.com/a/2185331/922323>

--- End Message ---
--- Begin Message ---
On Wed, Apr 17, 2013 at 3:59 PM, Micky Hulse <rgmi...@gmail.com> wrote:
> You might need to turn on the short tag option
> in your conf file.

Sorry, ini file, not conf. Been a long day. :D

I guess I should have asked if short tags are turned on for your 5.3.3?

--- End Message ---
--- Begin Message ---
It is the equivalent of <?php echo $var; ?>  it's just easier to type and read 
IMHO. For a while people were freaking out that they thought it would be 
deprecated, but that is not (nor ever will be) the case.

> -----Original Message-----
> From: Larry Martell [mailto:larry.mart...@gmail.com]
> Sent: Wednesday, April 17, 2013 3:51 PM
> To: PHP General
> Subject: [PHP] <?=$var?>
> 
> Continuing in my effort to port an app from PHP version 5.1.6 to 5.3.3, the
> app uses this construct all over the place when building
> links:
> 
> <?=$var?>
> 
> I never could find any documentation for this, but I assumed it was some
> conditional thing - use $var if it's defined, otherwise use nothing. In 5.1.6 
> it
> seems to do just that. But in 5.3.3 I'm not getting the value of $var even
> when it is defined. Has this construct been deprecated? Is there now some
> other way to achieve this?
> 
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
Ah, I see now. Sorry, I must have read the original question wrong.

There's a good thread on stack about short tags:

"Are PHP short tags acceptable to use?"
<http://stackoverflow.com/questions/200640/are-php-short-tags-acceptable-to-use>

Which kinda links to the docs:

"PHP tags"
<http://www.php.net/manual/en/language.basic-syntax.phptags.php>

--- End Message ---
--- Begin Message ---
Hi guys,

i have a string like this:
$string = \uc548\ub155\ud558\uc138\uc694
(Korean words that say "hello world" in English).
i got no luck when I tried with
Korean. 'UCS-2BE' to 'UTF-8' encoding conversion didn't work. i also
tried with ISO-2022-KR and EUC-KR to 'UTF-8' , but no luck either.
It should be 안녕하세요!

How can I convert that $string to Korean's character?




my regards,

Marco

--- End Message ---

Reply via email to