[PHP] utf8_decode() not working, conflicts with urlencode()

2011-08-30 Thread Merlin Morgenstern

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.''.$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.


Thank you for any help on that!

Merlin

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



Re: [PHP] utf8_decode() not working, conflicts with urlencode()

2011-08-30 Thread 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.''.$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)


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



[PHP] correct character decoding

2011-08-30 Thread Merlin Morgenstern

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.''.$output.''.$output2;
echo 'output 2';

echo '';
// latin 1
$input = urldecode('%DCbersetzung+franz');
$out = trim(utf8_encode($input));
$out2 = urlencode($out);
echo $input.''.$out.''.$out2;
echo 'output 2';


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



Re: [PHP] utf8_decode() not working, conflicts with urlencode()

2011-08-30 Thread Merlin Morgenstern

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.''.$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.


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



Re: [PHP] correct character decoding

2011-08-30 Thread 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


2011/8/30 Merlin Morgenstern 

> 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.''.$output.''.$**output2;
> echo 'output 2';
>
> echo '';
> // latin 1
> $input = urldecode('%DCbersetzung+**franz');
> $out = trim(utf8_encode($input));
> $out2 = urlencode($out);
> echo $input.''.$out.''.$**out2;
> echo 'output 2';
>
>
> 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
>
>


Re: [PHP] correct character decoding

2011-08-30 Thread Merlin Morgenstern

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 >


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.''.$output.''.$output2;
echo 'output 2';

echo '';
// latin 1
$input = urldecode('%DCbersetzung+franz');
$out = trim(utf8_encode($input));
$out2 = urlencode($out);
echo $input.''.$out.''.$out2;
echo 'output 2';


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






Re: [PHP] Code should be selv-maintaining!

2011-08-30 Thread Tedd Sperling
On Aug 29, 2011, at 4:32 PM, George Langley wrote:

> "The One True Brace 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




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



Re: [PHP] Code should be selv-maintaining!

2011-08-30 Thread Richard Quadling
On 30 August 2011 15:04, Tedd Sperling  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

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



[PHP] Books on PHP guts

2011-08-30 Thread Larry Garfield
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


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



Re: [PHP] Books on PHP guts

2011-08-30 Thread Daniel Brown
On Tue, Aug 30, 2011 at 13:19, Larry Garfield  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

-- 

Network Infrastructure Manager
http://www.php.net/

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



Re: [PHP] Code should be selv-maintaining!

2011-08-30 Thread Robert Cummings

On 11-08-30 11:36 AM, Richard Quadling wrote:

On 30 August 2011 15:04, Tedd Sperling  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 -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.

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



Re: [PHP] Code should be selv-maintaining!

2011-08-30 Thread David Harkness
I don't always use braces, but when I do I use Compact Control Readability
style. Stay coding, my friends.


RE: [PHP] Code should be selv-maintaining!

2011-08-30 Thread Daevid Vincent
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-general@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.


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



RE: [PHP] Code should be selv-maintaining!

2011-08-30 Thread Jen Rasmussen
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-general@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.


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



Re: [PHP] Code should be selv-maintaining!

2011-08-30 Thread Richard Quadling
On 30 August 2011 20:09, Robert Cummings  wrote:
> You're just saying that so Tedd will be your friend!! Come now, let's be
> honest with everyone... Whitesmith's is -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

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



Re: [PHP] Code should be selv-maintaining!

2011-08-30 Thread Jason Pruim

On Aug 30, 2011, at 6:25 PM, Richard Quadling wrote:

> On 30 August 2011 20:09, Robert Cummings  wrote:
>> You're just saying that so Tedd will be your friend!! Come now, let's be
>> honest with everyone... Whitesmith's is -GLEE! ;)
> 
> Beauty is in the eye of the beholder.

I always thought that was beer holder?

Is it friday yet? ;)


Jason Pruim
li...@pruimphotography.com


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



Re: [PHP] Code should be selv-maintaining!

2011-08-30 Thread Matt Graham
From:  David Harkness 
> I don't always use braces, but when I do I use Compact Control Readability
> style. Stay coding, my friends.

...and when you use CCR style, you can sing, "I see a bad brace a-risin'"?

-- 
Matt G / Dances With Crows
The Crow202 Blog:  http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see


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