php-general Digest 30 Aug 2011 22:25:26 -0000 Issue 7462

Topics (messages 314649 through 314662):

Re: utf8_decode() not working, conflicts with urlencode()
        314649 by: Per Jessen
        314651 by: Merlin Morgenstern

correct character decoding
        314650 by: Merlin Morgenstern
        314652 by: Louis Huppenbauer
        314653 by: Merlin Morgenstern

Re: Code should be selv-maintaining!
        314654 by: Tedd Sperling
        314655 by: Richard Quadling
        314658 by: Robert Cummings
        314659 by: David Harkness
        314660 by: Daevid Vincent
        314661 by: Jen Rasmussen
        314662 by: Richard Quadling

Books on PHP guts
        314656 by: Larry Garfield
        314657 by: Daniel Brown

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 ---
Merlin Morgenstern wrote:

> Hi there,
> 
> I am having some trouble with utf8_decode(). Somehow the function
> returns output=input
> 
> e.g.:
> $input = '%20%C3%9Cbersetzung%20franz';
> $output = utf8_decode($input);
> echo $input.'<br>'.$output;
> 
> My goal is to decode the utf8, trim the input and encode with
> urlencode();
> 
> This is the string which I would like to get: %C3%9Cbersetzung+franz
> 
> Trim does not work and if I place urlencode() directly on the input it
> will encode the % sign to %25 and produce therfore a mixture of
> encodings.

It seems to me that you're probably missing a urldecode() on $input
before you attempt to decode the utf8 chars ?



-- 
Per Jessen, Zürich (17.9°C)


--- End Message ---
--- Begin Message ---
Am 30.08.2011 12:11, schrieb Per Jessen:
Merlin Morgenstern wrote:

Hi there,

I am having some trouble with utf8_decode(). Somehow the function
returns output=input

e.g.:
$input = '%20%C3%9Cbersetzung%20franz';
$output = utf8_decode($input);
echo $input.'<br>'.$output;

My goal is to decode the utf8, trim the input and encode with
urlencode();

This is the string which I would like to get: %C3%9Cbersetzung+franz

Trim does not work and if I place urlencode() directly on the input it
will encode the % sign to %25 and produce therfore a mixture of
encodings.

It seems to me that you're probably missing a urldecode() on $input
before you attempt to decode the utf8 chars ?



That's right, this was missing. Thank you. However, this leeds to another problem which I described in a another posting.
--- End Message ---
--- Begin Message ---
Hi there,

I am trying to find a solution for decoding the same string from 2 different character sets (UTF-8, Latin-1)

Looks like in the case of latin-1 I need to add utf8_encode before to get the same results. Here is an example

// utf-8
$input = urldecode('%20%C3%9Cbersetzung%20franz');
$output = trim(($input));
$output2 = urlencode($output);
echo $input.'<br>'.$output.'<br>'.$output2;
echo '<a href="'.$output2.'">output 2</a>';

echo '<hr>';
// latin 1
$input = urldecode('%DCbersetzung+franz');
$out = trim(utf8_encode($input));
$out2 = urlencode($out);
echo $input.'<br>'.$out.'<br>'.$out2;
echo '<a href="'.$out2.'">output 2</a>';


The latin-1 seems to need the utf8-encode to get the same result. Has anybody an idea on how to solve this? I need a function that works for latin-1 and UTF-8.

Thank you in advance for any help,

Merlin

--- End Message ---
--- Begin Message ---
Why don't you just check if the string is utf8 or not, and change convert it
accordingly?

$out = trim((mb_detect_encoding($input, 'UTF-8', 'ISO-8859-1') == 'UTF-8' ?
$input : utf8_encode($input)));

It may not be the most elegant version, but I can't think of anything
simpler right now.

sincerely
louis


2011/8/30 Merlin Morgenstern <merlin.morgenst...@googlemail.com>

> Hi there,
>
> I am trying to find a solution for decoding the same string from 2
> different character sets (UTF-8, Latin-1)
>
> Looks like in the case of latin-1 I need to add utf8_encode before to get
> the same results. Here is an example
>
> // utf-8
> $input = urldecode('%20%C3%**9Cbersetzung%20franz');
> $output = trim(($input));
> $output2 = urlencode($output);
> echo $input.'<br>'.$output.'<br>'.$**output2;
> echo '<a href="'.$output2.'">output 2</a>';
>
> echo '<hr>';
> // latin 1
> $input = urldecode('%DCbersetzung+**franz');
> $out = trim(utf8_encode($input));
> $out2 = urlencode($out);
> echo $input.'<br>'.$out.'<br>'.$**out2;
> echo '<a href="'.$out2.'">output 2</a>';
>
>
> The latin-1 seems to need the utf8-encode to get the same result. Has
> anybody an idea on how to solve this? I need a function that works for
> latin-1 and UTF-8.
>
> Thank you in advance for any help,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Am 30.08.2011 14:12, schrieb Louis Huppenbauer:
Why don't you just check if the string is utf8 or not, and change convert it accordingly?

$out = trim((mb_detect_encoding($input, 'UTF-8', 'ISO-8859-1') == 'UTF-8' ? $input : utf8_encode($input)));

It may not be the most elegant version, but I can't think of anything simpler right now.

sincerely
louis


Hello Louis, thank you that solved the problem. Looks like I did not use the mb_detect_encoding properly in my tests.

Regards, Merlin



2011/8/30 Merlin Morgenstern <merlin.morgenst...@googlemail.com <mailto:merlin.morgenst...@googlemail.com>>

    Hi there,

    I am trying to find a solution for decoding the same string from 2
    different character sets (UTF-8, Latin-1)

    Looks like in the case of latin-1 I need to add utf8_encode before
    to get the same results. Here is an example

    // utf-8
    $input = urldecode('%20%C3%9Cbersetzung%20franz');
    $output = trim(($input));
    $output2 = urlencode($output);
    echo $input.'<br>'.$output.'<br>'.$output2;
    echo '<a href="'.$output2.'">output 2</a>';

    echo '<hr>';
    // latin 1
    $input = urldecode('%DCbersetzung+franz');
    $out = trim(utf8_encode($input));
    $out2 = urlencode($out);
    echo $input.'<br>'.$out.'<br>'.$out2;
    echo '<a href="'.$out2.'">output 2</a>';


    The latin-1 seems to need the utf8-encode to get the same result.
    Has anybody an idea on how to solve this? I need a function that
    works for latin-1 and UTF-8.

    Thank you in advance for any help,

    Merlin

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




--- End Message ---
--- Begin Message ---
On Aug 29, 2011, at 4:32 PM, George Langley wrote:

> "The One True Brace Style":
> 
> <http://en.wikipedia.org/wiki/Indent_style>
> 
> Didn't know there was a name for the way I learned to indent! Make sense to 
> me - looks so much cleaner and less scrolling/printing.
>       And, I already add a comment to confirm the end brace:
> 
> } // end if($myVar)
> 
> to clarify any long nests.
> 
> George

To all:

I prefer the Whitesmiths style:

http://rebel.lcc.edu/sperlt/citw229/brace-styles.php

But "style" is really up to the individual -- what works best for you is the 
"best" (unless it's a team effort or the clients demand).

Cheers,

tedd

---

t...@sperling.com
http://sperling.com




--- End Message ---
--- Begin Message ---
On 30 August 2011 15:04, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
> To all:
>
> I prefer the Whitesmiths style:
>
> http://rebel.lcc.edu/sperlt/citw229/brace-styles.php
>
> But "style" is really up to the individual -- what works best for you is the 
> "best" (unless it's a team effort or the clients demand).
>
> Cheers,
>
> tedd

At last!!!! Someone's code I could read without having to reformat it
every bloody time!!!

http://en.wikipedia.org/wiki/Indent_style#Whitesmiths_style

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

--- End Message ---
--- Begin Message ---
On 11-08-30 11:36 AM, Richard Quadling wrote:
On 30 August 2011 15:04, Tedd Sperling<tedd.sperl...@gmail.com>  wrote:
To all:

I prefer the Whitesmiths style:

http://rebel.lcc.edu/sperlt/citw229/brace-styles.php

But "style" is really up to the individual -- what works best for you is the 
"best" (unless it's a team effort or the clients demand).

Cheers,

tedd

At last!!!! Someone's code I could read without having to reformat it
every bloody time!!!

http://en.wikipedia.org/wiki/Indent_style#Whitesmiths_style

You're just saying that so Tedd will be your friend!! Come now, let's be honest with everyone... Whitesmith's is UUUUUUUUHHHH-GLEE! ;)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
I don't always use braces, but when I do I use Compact Control Readability
style. Stay coding, my friends.

--- End Message ---
--- Begin Message ---
LOLercopter! 

> -----Original Message-----
> From: David Harkness [mailto:davi...@highgearmedia.com]
> Sent: Tuesday, August 30, 2011 12:57 PM
> To: Robert Cummings
> Cc: rquadl...@gmail.com; Tedd Sperling; php-gene...@lists.php.net
> Subject: Re: [PHP] Code should be selv-maintaining!
> 
> I don't always use braces, but when I do I use Compact Control Readability
> style. Stay coding, my friends.


--- End Message ---
--- Begin Message ---
David Harkness ...you must be...
the "most interesting coder in the world" ;)

-----Original Message-----
From: David Harkness [mailto:davi...@highgearmedia.com] 
Sent: Tuesday, August 30, 2011 2:57 PM
To: Robert Cummings
Cc: rquadl...@gmail.com; Tedd Sperling; php-gene...@lists.php.net
Subject: Re: [PHP] Code should be selv-maintaining!

I don't always use braces, but when I do I use Compact Control Readability
style. Stay coding, my friends.


--- End Message ---
--- Begin Message ---
On 30 August 2011 20:09, Robert Cummings <rob...@interjinn.com> wrote:
> You're just saying that so Tedd will be your friend!! Come now, let's be
> honest with everyone... Whitesmith's is UUUUUUUUHHHH-GLEE! ;)

Beauty is in the eye of the beholder.


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

--- End Message ---
--- Begin Message --- Hi folks. I'm not looking to write new PHP extensions per se, but am looking to better grok the guts of PHP itself. (That's a first step on the way to writing new extensions, though. Gateway drug!) I'm especially interested in the memory/performance implications of various techniques.

Are there any good books on the subject that would be of help? I'm familiar with Sara Goleman's book[1], which has generally good reviews, but it's several years old now and I'm not sure if there's anything newer that covers PHP developments since the 5.0 days.

Any suggestions?

--Larry Garfield

[1] http://www.barnesandnoble.com/w/extending-and-embedding-php-sara-golemon/1006978211
--- End Message ---
--- Begin Message ---
On Tue, Aug 30, 2011 at 13:19, Larry Garfield <la...@garfieldtech.com> wrote:
> Hi folks.  I'm not looking to write new PHP extensions per se, but am
> looking to better grok the guts of PHP itself.  (That's a first step on the
> way to writing new extensions, though.  Gateway drug!)  I'm especially
> interested in the memory/performance implications of various techniques.
>
> Are there any good books on the subject that would be of help?  I'm familiar
> with Sara Goleman's book[1], which has generally good reviews, but it's
> several years old now and I'm not sure if there's anything newer that covers
> PHP developments since the 5.0 days.
>
> Any suggestions?

    Actually, Sara's book should still be the most relevant on the
subject (at least of books in print).  There's another by an author
named Blake Schwendiman, named "Building Custom PHP Extensions" from
2003[1], which may be of some help, but that would be more
PHP4-centric, or previewing PHP5 RC's at best --- which wouldn't be
reliable in and of itself.  That said, as an additional resource on
the subject, it may be of some use.  I haven't read it myself, and
just found it searching on Amazon now.

    All of that aside, obviously your best bet, knowing you, would be
trial-and-error.  I've written a few dozen extensions myself over the
years, and each and every time I've found out new and better ways of
doing things.  I'd start by writing extensions to optimize things you
use on a regular basis for clients or internally (such as redundant
database queries or encryption algorithms).  As for getting started,
Zend has a decent introduction[2] on the subject if you haven't yet
seen it.  It won't get as deep into the guts as you'd probably like,
but I'm not certain that there is anything on ink and paper.  For
that, your best bet would likely be the "Hacker's Guide" on
php.net[3].

    ^1: 
http://www.amazon.com/Building-Custom-Extensions-Blake-Schwendiman/dp/1411601882/ref=sr_1_2?ie=UTF8&qid=1314725705&sr=8-2
    ^2: http://devzone.zend.com/article/1021
    ^3: http://php.net/internals

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

--- End Message ---

Reply via email to