php-general Digest 27 May 2010 15:13:49 -0000 Issue 6767

Topics (messages 305559 through 305568):

Re: One more time about regexes
        305559 by: Adam Richardson
        305561 by: Andre Polykanine
        305562 by: Ford, Mike

Re: getaddrinfo() - what is the equivalent php function?
        305560 by: Per Jessen

Re: Convert UTF-8 to PHP defines
        305563 by: Andre Polykanine
        305564 by: Guus Ellenkamp
        305565 by: Ashley Sheridan

uploading file encoding error
        305566 by: Manolis Vlachakis
        305567 by: Ashley Sheridan
        305568 by: Ashley Sheridan

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, May 26, 2010 at 11:10 PM, Nilesh Govindarajan <li...@itech7.com>wrote:

> ---------- Forwarded message ----------
> From: Nilesh Govindarajan <li...@itech7.com>
> Date: Thu, May 27, 2010 at 8:40 AM
> Subject: Re: [PHP] One more time about regexes
> To: Andre Polykanine <an...@oire.org>
>
>
> On Thu, May 27, 2010 at 3:33 AM, Andre Polykanine <an...@oire.org> wrote:
> > Hello everyone,
> >
> > Sorry, but I'm asking one more time (since it's really annoying me and
> > I need to apply some really dirty hacks):
> > Is there a way making preg_replace() pass through the regex one single
> > time searching from left to right and not to erase what it has already
> > done?
> > I can give you a real task I'm accomplishing but the tasks requiring
> > that tend to multiply...
> > Thanks a lot!
> >
> > --
> > With best regards from Ukraine,
> > Andre
> > Http://oire.org/ - The Fantasy blogs of Oire
> > Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @
> jabber.org
> > Yahoo! messenger: andre.polykanine; ICQ: 191749952
> > Twitter: http://twitter.com/m_elensule
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> If you don't want to replace the stuff it has searched then use preg_match
> !
>
> --
> Nilesh Govindarajan
> Facebook: nilesh.gr
> Twitter: nileshgr
> Website: www.itech7.com
>
>
>
> --
> Nilesh Govindarajan
> Facebook: nilesh.gr
> Twitter: nileshgr
> Website: www.itech7.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
If I'm understanding correctly, Andre, you want to perform a replace
operation, but you're observing that there's an element of recursion
happening (e.g., you replace one item with its replacement, and then the new
replacement is also replaced.)

To my knowledge, this won't happen with a standard preg_replace():

$string = 'Bil & Tom & Phil';
$pattern = '/&/';
$replacement = '&amp;';
// outputs Bil &amp; Tom &amp; Phil
echo preg_replace($pattern, $replacement, $string);

However, if you're using arrays to pass in the patterns and replacements,
then one array item could later be replaced by another (see comment and
example on this page by info at gratisrijden dot nl):
http://php.net/manual/en/function.preg-replace.php

If that's the case, you have to carefully structure the order of the array
items so-as to preclude one replacement having the opportunity to override a
subsequent replacement.

Sorry if I misunderstood.  You might want to create a simple example of code
showing what you're working through.

Adam


-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
Hello Adam,

You did understand me exactly and perfectly).
Ordering arrays is a good idea but I don't know how to do that
exactly.
For instance, there's a cypher called Polybius square. You write in
the alphabet in a grid like this:
1 a b c d e
2 f g h i j
3 k l m n o
4 p q r s t
5 u v w x y
6 z

There is a way where i/j are equal to make a 5 by 5 square but for me
it's equal since I'm working with a 33-letter Russian alphabet, so no
way to make it a perfect square.
Anyway, a letter has two coordinates and is represented by a two-digit
number. For example, E is 15, K is 21, Z is 61 and so on.
So we have a word, say, PHP. It will look like this: 412341.
What does preg_replace do? Exactly, it's searching 41, then 12, then
23, and so on.
I tried to make a loop:
$length=mb_strlen($str);
for ($i=0; $i<$length; $i+=2) {
$pair=mb_substr($str, $i, 2);
$pair=preg_replace($numbers, $letters, $str);
}

It already smells something not good, but anyway.
If I do that, I have one more problem: say, we have a phrase "PHP is
the best". So we crypt it and get:
412341 2444 452315 12154445
Then the parser begins: "41=>p, 23=>h, 41=>p, (attention!) \s2=>...."
I marked a whitespace as \s so you see what happens.
I might split the string by spaces but I can't imagine what a user
inputs: it might be a dash, for example...
Sorry for such a long message but I'm really annoyed with this
preg_replace's behavior. And it's not the only one task to
accomplish...
Thanks a lot!

-- 
With best regards from Ukraine,
Andre
Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ 
jabber.org
Yahoo! messenger: andre.polykanine; ICQ: 191749952
Twitter: m_elensule

----- Original message -----
From: Adam Richardson <simples...@gmail.com>
To: php-gene...@lists.php.net <php-gene...@lists.php.net>
Date: Thursday, May 27, 2010, 7:56:28 AM
Subject: [PHP] One more time about regexes

On Wed, May 26, 2010 at 11:10 PM, Nilesh Govindarajan <li...@itech7.com>wrote:

> ---------- Forwarded message ----------
> From: Nilesh Govindarajan <li...@itech7.com>
> Date: Thu, May 27, 2010 at 8:40 AM
> Subject: Re: [PHP] One more time about regexes
> To: Andre Polykanine <an...@oire.org>
>
>
> On Thu, May 27, 2010 at 3:33 AM, Andre Polykanine <an...@oire.org> wrote:
> > Hello everyone,
> >
> > Sorry, but I'm asking one more time (since it's really annoying me and
> > I need to apply some really dirty hacks):
> > Is there a way making preg_replace() pass through the regex one single
> > time searching from left to right and not to erase what it has already
> > done?
> > I can give you a real task I'm accomplishing but the tasks requiring
> > that tend to multiply...
> > Thanks a lot!
> >
> > --
> > With best regards from Ukraine,
> > Andre
> > Http://oire.org/ - The Fantasy blogs of Oire
> > Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @
> jabber.org
> > Yahoo! messenger: andre.polykanine; ICQ: 191749952
> > Twitter: http://twitter.com/m_elensule
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> If you don't want to replace the stuff it has searched then use preg_match
> !
>
> --
> Nilesh Govindarajan
> Facebook: nilesh.gr
> Twitter: nileshgr
> Website: www.itech7.com
>
>
>
> --
> Nilesh Govindarajan
> Facebook: nilesh.gr
> Twitter: nileshgr
> Website: www.itech7.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
If I'm understanding correctly, Andre, you want to perform a replace
operation, but you're observing that there's an element of recursion
happening (e.g., you replace one item with its replacement, and then the new
replacement is also replaced.)

To my knowledge, this won't happen with a standard preg_replace():

$string = 'Bil & Tom & Phil';
$pattern = '/&/';
$replacement = '&amp;';
// outputs Bil &amp; Tom &amp; Phil
echo preg_replace($pattern, $replacement, $string);

However, if you're using arrays to pass in the patterns and replacements,
then one array item could later be replaced by another (see comment and
example on this page by info at gratisrijden dot nl):
http://php.net/manual/en/function.preg-replace.php

If that's the case, you have to carefully structure the order of the array
items so-as to preclude one replacement having the opportunity to override a
subsequent replacement.

Sorry if I misunderstood.  You might want to create a simple example of code
showing what you're working through.

Adam


-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com


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

> -----Original Message-----
> From: Andre Polykanine [mailto:an...@oire.org]
> Sent: 27 May 2010 09:14
> To: Adam Richardson
> Cc: php-gene...@lists.php.net
> Subject: Re[2]: [PHP] One more time about regexes
> 
> Hello Adam,
> 
> You did understand me exactly and perfectly).
> Ordering arrays is a good idea but I don't know how to do that
> exactly.
> For instance, there's a cypher called Polybius square. You write in
> the alphabet in a grid like this:
> 1 a b c d e
> 2 f g h i j
> 3 k l m n o
> 4 p q r s t
> 5 u v w x y
> 6 z
> 
> There is a way where i/j are equal to make a 5 by 5 square but for
> me
> it's equal since I'm working with a 33-letter Russian alphabet, so
> no
> way to make it a perfect square.
> Anyway, a letter has two coordinates and is represented by a two-
> digit
> number. For example, E is 15, K is 21, Z is 61 and so on.
> So we have a word, say, PHP. It will look like this: 412341.

Well, as you're wanting to replace pairs of digits, I'd search for exactly that 
-- but I think I'd use the e flag to employ a programmed replacement, thus:

    $str = "4123415 - 2444 452315 12154445!";
    $replaced = preg_replace("{(\d\d)}e", "polybius_decode('\\1')", $str);

    echo $replaced;

    function polybius_decode($pair) {

       static $polybius = array(
                                  '11'=>'a', 'b', 'c', 'd', 'e',
                                  '21'=>'f', 'g', 'h', 'i', 'j',
                                  '31'=>'k', 'l', 'm', 'n', 'o',
                                  '41'=>'p', 'q', 'r', 's', 't',
                                  '51'=>'u', 'v', 'w', 'x', 'y',
                                  '61'=>'z'
                               );
                                                
       return isset($polybius[$pair]) ? $polybius[$pair] : $pair;
    }

Seems to work: "php5 - is the best!". :)

Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--- End Message ---
--- Begin Message ---
Per Jessen wrote:

> AFAICT, gethostbyname() only works for ipv4 addresses, so that one is
> out - dns_get_record seems to be really for dns only, i.e. it does not
> look at /etc/hosts.  Is there a hph function that essentially just
> calls getaddrinfo() ?
> 

Wow, lots of answers to that one. 

Let me rephrase it then - what is the PHP interface to the system
resolver when support for IPv6 is required?  
Again, gethostbyname() only works for IPv4 and dns_get_record is not a
resolver interface, but a DNS interface. (AFAICT). 
 

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


--- End Message ---
--- Begin Message ---
Hello Guus,

Actually, we are using the same method here on http://oire.org/. We
have all of the language files in UTF8 format and everything seems to
be OK. Yes, unicode support in PHp laisse à désirer, like the French
say, but it does support UTF8 files.
-- 
With best regards from Ukraine,
Andre
Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ 
jabber.org
Yahoo! messenger: andre.polykanine; ICQ: 191749952
Twitter: m_elensule

----- Original message -----
From: Guus Ellenkamp <ellenkamp_g...@hotmail.com>
To: php-gene...@lists.php.net <php-gene...@lists.php.net>
Date: Wednesday, May 26, 2010, 5:20:59 PM
Subject: [PHP] Convert UTF-8 to PHP defines

We use PHP defines for defining text in different languages. As far as I 
know PHP files are supposed to be ASCII, not UTF-8 or something like that. 
What I want to make is a conversion program that would convert a given UTF-8 
file with the format

definetext1=this is a text in random UTF-8, probably arabic or similar text
definetext2=this is another text in random UTF-8, probably arabic or similar 
text

into a file with the following defines

define('definetext1',chr(<t_value>).chr(<h_value>).chr(<i_value>)...<chr(<x_value>).chr(<t_value>));
define('definetext2,chr(<t_value>).chr(<h_value>).chr(<i_value>)...<chr(<x_value>).chr(<t_value>));

Not sure if I'm using the correct chr/ord function, but I hope the above is 
clear enough to make clear what I'm looking for. Basically the output file 
should be ascii and not contain any utf-8.

Any advise? The html_special_chars did not seem to work for Vietnamese text 
I tried to convert, so something seems to get wrong with just reading an 
array of strings and converting the strings and putting them in defines. 



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


--- End Message ---
--- Begin Message ---
Thanks, but are you sure of that? I did some research a while ago and found 
that officially PHP files should be ascii and not have any specific 
character encoding. I believe it will work anyhow (did not try this one), 
but would like to stick with the standards.

"Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message 
news:1274883714.2202.228.ca...@localhost...
> On Wed, 2010-05-26 at 22:20 +0800, Guus Ellenkamp wrote:
>
>> We use PHP defines for defining text in different languages. As far as I
>> know PHP files are supposed to be ASCII, not UTF-8 or something like 
>> that.
>> What I want to make is a conversion program that would convert a given 
>> UTF-8
>> file with the format
>>
>> definetext1=this is a text in random UTF-8, probably arabic or similar 
>> text
>> definetext2=this is another text in random UTF-8, probably arabic or 
>> similar
>> text
>>
>> into a file with the following defines
>>
>> define('definetext1',chr(<t_value>).chr(<h_value>).chr(<i_value>)...<chr(<x_value>).chr(<t_value>));
>> define('definetext2,chr(<t_value>).chr(<h_value>).chr(<i_value>)...<chr(<x_value>).chr(<t_value>));
>>
>> Not sure if I'm using the correct chr/ord function, but I hope the above 
>> is
>> clear enough to make clear what I'm looking for. Basically the output 
>> file
>> should be ascii and not contain any utf-8.
>>
>> Any advise? The html_special_chars did not seem to work for Vietnamese 
>> text
>> I tried to convert, so something seems to get wrong with just reading an
>> array of strings and converting the strings and putting them in defines.
>>
>>
>>
>
>
> PHP files can contain utf-8, and in-fact is the preference of most
> developers I know of.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
> 



--- End Message ---
--- Begin Message ---
On Thu, 2010-05-27 at 21:45 +0800, Guus Ellenkamp wrote:

> Thanks, but are you sure of that? I did some research a while ago and found 
> that officially PHP files should be ascii and not have any specific 
> character encoding. I believe it will work anyhow (did not try this one), 
> but would like to stick with the standards.
> 
> "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message 
> news:1274883714.2202.228.ca...@localhost...
> > On Wed, 2010-05-26 at 22:20 +0800, Guus Ellenkamp wrote:
> >
> >> We use PHP defines for defining text in different languages. As far as I
> >> know PHP files are supposed to be ASCII, not UTF-8 or something like 
> >> that.
> >> What I want to make is a conversion program that would convert a given 
> >> UTF-8
> >> file with the format
> >>
> >> definetext1=this is a text in random UTF-8, probably arabic or similar 
> >> text
> >> definetext2=this is another text in random UTF-8, probably arabic or 
> >> similar
> >> text
> >>
> >> into a file with the following defines
> >>
> >> define('definetext1',chr(<t_value>).chr(<h_value>).chr(<i_value>)...<chr(<x_value>).chr(<t_value>));
> >> define('definetext2,chr(<t_value>).chr(<h_value>).chr(<i_value>)...<chr(<x_value>).chr(<t_value>));
> >>
> >> Not sure if I'm using the correct chr/ord function, but I hope the above 
> >> is
> >> clear enough to make clear what I'm looking for. Basically the output 
> >> file
> >> should be ascii and not contain any utf-8.
> >>
> >> Any advise? The html_special_chars did not seem to work for Vietnamese 
> >> text
> >> I tried to convert, so something seems to get wrong with just reading an
> >> array of strings and converting the strings and putting them in defines.
> >>
> >>
> >>
> >
> >
> > PHP files can contain utf-8, and in-fact is the preference of most
> > developers I know of.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> > 
> 
> 
> 


Very sure, ever PHP file I ever make is always in utf8. The only problem
you might encounter is when outputting HTML, you should make sure that
you output the right text encoding headers, as some browsers won't
correctly detect it and can tend to output utf-8 characters as random
blocks and other characters.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
hallo there everyone!
i am uploading a file in a php applet i developed and i face a problem
while i upload greek named files..
have no problem with the english or so on files...
is there a way to use iconv or something else so as to solve my problem ?
my code looks like that...


$uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/****
/****/public_html/uploads/';
$file = $uploaddir . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
  echo "success";
} else {
echo "error";
}



thanx

-- 
Manolis Vlachakis

Nelly's Family Hotel
Visit    :   www.nellys-hotel.gr
              www.nellys.gr
Skype : manolis.vlachakis

--- End Message ---
--- Begin Message ---
On Thu, 2010-05-27 at 17:49 +0300, Manolis Vlachakis wrote:

> hallo there everyone!
> i am uploading a file in a php applet i developed and i face a problem
> while i upload greek named files..
> have no problem with the english or so on files...
> is there a way to use iconv or something else so as to solve my problem ?
> my code looks like that...
> 
> 
> $uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/****
> /****/public_html/uploads/';
> $file = $uploaddir . basename($_FILES['uploadfile']['name']);
> if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
>   echo "success";
> } else {
> echo "error";
> }
> 
> 
> 
> thanx
> 


I assume that the file upload works with other files?

Firstly, what is the filesystem that you're using, and the operating
system. Windows filesystems are very limiting on what characters you can
use.

If you have it working with another file, have you tried renaming that
to use characters which you think are causing the problems?

Lastly, what exactly is the error code returned from the $_FILES array?

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Thu, 2010-05-27 at 18:03 +0300, Manolis Vlachakis wrote:

> i am using gentoo
> 
> and on the server side i cant see either the files with their greek
> names
> but i had no problem in the past handling them even though
> i couldn't see them...
> 
> 
> my servers log say that they uploaded the file but no
> error occurred...
> is there another way to upload a file with that script or i should try
> to find something else to solve my problem....

[/SNIP]

> 
> 
> -- 
> Manolis Vlachakis
> 
> Nelly's Family Hotel 
> Visit    :   www.nellys-hotel.gr
>               www.nellys.gr
> Skype : manolis.vlachakis
> 

Gentoo I believe uses the ext3 filesystem by default, which should be
perfectly capable of handling Greek characters.

What happens when you upload a normal small file now with non-Greek
characters and see what happens? Does that upload correctly?

Output the $_FILES array and look to see if the error code is anything
other than 0. If it is, that means there's a problem with the upload,
which probably won't show on the server log.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---

Reply via email to