You are here: Re: php cli command ... « PHP Programming Language « IT news, forums, messages
Re: php cli command ...

Posted by Julien CROUZET on 11/11/44 11:40

Le 21/02/2006, dbee a supposé :
> Julien CROUZET wrote:
>> dbee a pensé très fort :
>>> Julien CROUZET wrote:
>>>> Il se trouve que dbee a formulé :
>>>>> Has anyone any idea why this doesn't work ?
>>>>>
>>>>> while read file ; do php -r 'urlencode($file);' ; done > file
>>>>>
>>>>> I've also tried
>>>>>
>>>>> cat file | php -r 'urlencode($0);' > file
>>>>>
>>>>> no luck there either ??
>>>>
>>>> 1°) This should give you a trick :
>>>>
>>>> $> while read file ; do echo '$file'; done
>>>> test
>>>> $file
>>>>
>>>> $> while read file ; do echo "$file"; done
>>>> test
>>>> test
>>>>
>>>> $variables are not interpreted in a single quote context, it does
>>>> in a DOUBLE quotes one (like in PHP).
>>>>
>>>>
>>>> 2°) urlencode($file) returns a string, it does not output anything,
>>>> echo does.
>>>> => echo urlencode($file);
>>>>
>>> Thanks julien,
>>>
>>> 1) php cli only accepts single quotes I'm afraid
>>>
>>
>> $>sh
>> $>echo "encode this : %}&" | while read file ; do php -r "echo
>> urlencode('$file');" ; done
>> encode+this+%3A+%25%7D%26
>>
> Merci beaucoup,
>
> Excellent thanks julien

YW.

In addition, if what you searched was how to SPECIFICALLY grep a shell
variable from PHP when run as CLI ; you NEED to export(builtin) it,
else your shell won't pass it in the **environ while executing php
binary.
Here is a (dummy) example :

$>echo "encode this : %}&" | while read file ; do php -r
'var_dump($_SERVER['file']);' ; done

NULL


$>echo "encode this : %}&" | while read file ; do export file && php -r
'var_dump($_SERVER['file']);' ; done

string(17) "encode this : %}&"

Greetings,

--
Julien CROUZET - DSI Theoconcept
julien.crouzet@/enlever ca\theoconcept.com
http://www.theoconcept.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация