php-general Digest 17 Mar 2008 08:26:16 -0000 Issue 5352

Topics (messages 271656 through 271676):

Re: Objects as array key names??
        271656 by: Nathan Nobbe
        271657 by: Nathan Nobbe
        271659 by: Jim Lucas
        271660 by: Jim Lucas
        271663 by: Robert Cummings
        271664 by: Jim Lucas
        271669 by: Jim Lucas

Re: Newbie ' If Statement' Question
        271658 by: cool7.hosting4days.com
        271661 by: Al

Re: DOM - Question about \0
        271662 by: Casey
        271665 by: Rob Richards

__halt_compiler()
        271666 by: Casey

problem with this regex to remove img tag...
        271667 by: Ryan A
        271668 by: M. Sokolewicz
        271670 by: Jim Lucas
        271671 by: M. Sokolewicz
        271672 by: M. Sokolewicz
        271674 by: Ryan A

How to pass POST data to php-cgi
        271673 by: Hui Chen
        271675 by: Hui Chen

Re: GD / Pixel Font Rendering
        271676 by: Jochem Maas

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
On Sat, Mar 15, 2008 at 6:02 PM, Jim Lucas <[EMAIL PROTECTED]> wrote:

> It has been brought to my attention that with Perl and Ruby, you can use
> Objects as the value of the key within an array.  The examples that were
> shown to me make me think that this would be an awesome ability to have
> within PHP.


this is essentially already possible, w/ some limitations due to type
checking w/in php.  remember that spl thing that everyone loves to bash?
well thats what makes this remotely possible.  you can put elements in using
array notation and objects as keys, but thats about as far as it goes.  some
of the global functions like array_key_exists() dont work because they check
the type of the $needle argument internally.  also, iteration via foreach
does not work correctly.  implementing the Iterator interface to tell php
how to iterate over the structure works as expected however a strange error
is raised when trying to retrieve the current key: PHP Warning:  Illegal
type returned from ObjectArray::key().  LAME, *sigh*.  anyway, its still
pretty cool, and part of what youre looking for.  i might see if marcus
could tell me something about a condition w/in the code for key() inside of
php that would allow this to actually work, because imho, if its overridden
the internal check thats currently in place should be bypassed.  also
forgive the long post (theres code to follow ;))

<?php
class ObjectArray implements ArrayAccess, Countable, Iterator{
        private $indexes = array();
        private $values = array();
        private $curOffset = -1;
        private $totalElements = 0;

/// Countable interface
        public function count() {
                return $this->totalElements;
        }

/// ArrayAccess interface
        public function offsetExists($offset) {
                $offsetExists = false;
                foreach($this->indexes as $curIndex => $curObj) {
                        if($curObj === $offset) {
                                $offsetExists = true;
                                $this->curOffset = $curIndex;
                                break;
                        }
                }
                return $offsetExists;
        }

        public function offsetGet($offset) {
                if($this->offsetExists($offset)) {
                        return $this->values[$this->curOffset];
                }
        }

        public function offsetSet($offset, $value) {
                if(!$this->offsetExists($offset)) {     // grab index of
offset
                        /// set value of offset for first time
                        $this->indexes[] = $offset;
                        $this->values[] = $value;
                        $this->totalElements++;
                } else {
                        /// update value of offset
                        $this->values[$this->curOffset] = $value;
                }
        }

        public function offsetUnset($offset) {
                if($this->offsetExists($offset)) {
                        unset($this->indexes[$this->curOffset]);
                        unset($this->values[$this->curOffset]);
                        $this->totalElements--;
                }
        }

/// Iterator interface
        public function current() {
                return $this->values[$this->curOffset];
        }

        public function key() {
                return $this->indexes[$this->curOffset];
        }

        public function next() {
                $this->curOffset++;
        }

        public function rewind() {
                $this->curOffset = 0;
        }

        public function valid() {
                $isValid = false;
                if(isset($this->indexes[$this->curOffset]) &&
                        isset($this->values[$this->curOffset])) {
                        $isValid = true;
                }
                return $isValid;
        }
}

$objArr = new ObjectArray();

/// make $a & $c the same so == comparison should succeed
$a = new StdClass();
$b = new StdClass();
$b->a = 'spl is the shit ;)';
$c = new stdClass();

// test putting a value in w/ object as index
$objArr[$a] = 5;
echo $objArr[$a] . PHP_EOL;
// test changing the value
$objArr[$a] = 6;
echo $objArr[$a] . PHP_EOL;
// note we can put in objs that pass == test, because internally
// we use ===
$objArr[$c] = 7;

echo 'count: ' . count($objArr) . PHP_EOL;
$objArr[$b] = 8;
echo 'count: ' . count($objArr) . PHP_EOL;

var_dump($objArr[$a] == $objArr[$b]);   // false
var_dump($objArr[$a] == $objArr[$c]);   // false

/// broken even w/ Iterator implemented :(
foreach($objArr as $key => $val) {
        if($a === $key) {
                echo "keyFound: {$objArr[$a]}" . PHP_EOL;
                break;
        }
}

-nathan

--- End Message ---
--- Begin Message ---
after talking w/ marcus it sounds like theyve explicitly decided not to
support objects in the aforementioned context.

-nathan

--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
Imagine 200 customers in your example... your example will hit the DB
201 times. The above hits the DB twice.

My code was intended to get the concept across. Thanks for the suggestions though.



--- End Message ---
--- Begin Message ---
Richard Heyes wrote:
Hi,

Going off the subject alone, you might want to investigate the __tostring() magic method that you can define to handle objects being cast to a string. Also, there's a whole bunch of magic methods that you can use to handle PHP operations on user defined objects:

http://uk.php.net/manual/en/language.oop5.magic.php


I think I understand where you are going with your response, but still I don't see how incorporating __toString() into the equation would help. I would still loose reference to the original object data.

Jim

--- End Message ---
--- Begin Message ---
On Sun, 2008-03-16 at 11:42 -0700, Jim Lucas wrote:
> Robert Cummings wrote:
> > Imagine 200 customers in your example... your example will hit the DB
> > 201 times. The above hits the DB twice.
> 
> My code was intended to get the concept across.  Thanks for the 
> suggestions though.

Ah, ok. I've inherited projects in the past where the kind of code you
showed was defacto... except the number of queries made to render a
homepage wasn't 201 it was thousands. In one case someone built a
category pullout menu that was generating close to 18000 queries. That
holds my record for inefficient DB queries.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
On Sun, 2008-03-16 at 11:42 -0700, Jim Lucas wrote:
Robert Cummings wrote:
Imagine 200 customers in your example... your example will hit the DB
201 times. The above hits the DB twice.
My code was intended to get the concept across. Thanks for the suggestions though.

Ah, ok. I've inherited projects in the past where the kind of code you
showed was defacto... except the number of queries made to render a
homepage wasn't 201 it was thousands. In one case someone built a
category pullout menu that was generating close to 18000 queries. That
holds my record for inefficient DB queries.

Cheers,
Rob.

That beats my example. My current project at work, rebuilding the billing system, topped at about 6000 queries in one page. But, that page could vary by the number of services/locations a given customer has, the large the number of services/locations, the larger the number of queries. Right now, one customer has about 3500 services in 5 different locations. I have been able to pair the number of queries down to a dozen or so. Not sure what the previous developer was thinking.... The DB is much happier!

Jim

--- End Message ---
--- Begin Message --- Sorry for the long post, but I thought it would explain much of my thinking... Anyway, here we go...

Jeremy Mcentire wrote:
You may have meant the while loop to iterate over $row = fetch_object($res) ...

You are correct, I was simply trying to get the concept across. But you are correct, I should have used *_object() instead.

The basic idea is to always end up with an array of objects.


You could also create a data object associated with customer that makes use of overloading functions -- or whatever you kids are calling them these days to allow:

$customer = new Customer(78); // Load customer with ID 78.
$customer->loadLocations(); // Loads related locations.
$customer->location[n]; // Returns nth location.
$customer->location('home'); // Returns the location dubbed "home."
// You can have location loadLocations() if they're not already set.


This is how I currently do things. I have customer objects, contact objects, location objects, service objects, attribute objects, etc... and they all have similar getXXX() methods.

# Returns me all customers
$customers = new Customers();
$customers->getCustomers();
echo $customers; // __toString() returns the total number of customers


# Returns me a specific customer, or creates a new/empty customer object
$customer = new Customer([ int $customer_id ]);
$customer->getLocations(); // Returns locations objects
echo $customer; // __toString() returns the name of the customer


# Returns an object that will allow me to get all customer locations
$locations = new Locations( int $customer_id );
$locations->getLocations(); // Returns array of location objects
echo $locations; // __toString() returns the total number of locations


# Returns a location object, or creates a new/empty location object
$location = new Location([ int $location_id ]);
$location->getServices(); // Returns array of service objects
$location->getCustomer(); // Returns customer object
echo $location; // __toString() returns the name of the location


# Returns an object that contains all services to a given location
$services = new Services( int $location_id );
$services->getServices(); // Returns array of service objects
echo $services; // __toString() returns the total number of services


# Returns a service object, or creates a new/empty service object
$service = new Service([ int $service_id ]);
$service->getAttributes(); // Returns array of attribute objects
$service->getLocation(); // Returns location object
echo $service; // __toString() returns the name of the service


# Returns an object that contains all service attributes
$attributes = new Attributes( int $service_id );
$attributes->getAttributes(); // Returns array of attribute objects
echo $attributes; // __toString() returns the total number of attributes


# Returns a service object, or creates a new/empty service object
$attribute = new Attribute([ int $attribute_id ]);
echo $attribute; // __toString() returns the value of the attribute


I have many other types of objects: logs, CDR's, tasks, tickets, etc...

The data object would have to make use of __get, __set, and __call.

Each of the above objects use these functions and cleans data being extracted from and validates data being pushed into the said object.

The objects contains regex, string length, number range, and other types of checks before the data is accepted into the object.


Hereby, the locations aren't indexed by the object, but are elements in a member array.

Correct! And this member array/object is only created upon request. Therefor the overhead of creating said array/object is only felt when needed.

Jim Lucas

--- End Message ---
--- Begin Message ---
Thank you everybody for these great tips!


--
Thanks - RevDave
Cool7 @ hosting4days . com
[db-lists]




--- End Message ---
--- Begin Message ---
Here's how I'd do it.

<?php
$row= $emp_row->getRecordId();//Or, you can put this inside the heredoc with {}

//heredoc
$str= <<<txt
<form name="edit" method="post" action="emp_edit_result2.php">
<input type="hidden" name="Status" value="Active" />
<input type="hidden" name="The_Date" value="" />
<input type="hidden" name="-recid" value="$row" />
<input type="submit" name="edit_submit" value="Activate" />
</form>
txt;

if (!empty($emp_row->getField('testfield')) print $str;
else print "Non Print";
?>


[EMAIL PROTECTED] wrote:
Hello Folks,

I would like to be able to wrap a 'form' inside a php 'if statement' -  so
that the form will appear if the 'if condition' is met.

-  most likely I cannot have a <?php tag inside another one - and am sure
I'm doing other things wrong also...
- now I get the error - Parse error: syntax error, unexpected T_STRING in...

Q:  What is the best way to accomplish this goal?


-----------------------

<?php if ($emp_row->getField('testfield') !="") {
    print "<form name="edit" method="post" action="emp_edit_result2.php">
<input type="hidden" name="Status" value="Active"/>
<input type="hidden" name="The_Date" value=""/>
<input type="hidden" name="-recid" value="<?php echo
$emp_row->getRecordId(); ?>">
<input type="submit" name="edit_submit" value="Activate">
</form>
";}else {print "Non Print";} ?>
--
Thanks - RevDave
Cool7 @ hosting4days . com
[db-lists]




--- End Message ---
--- Begin Message ---
On Sun, Mar 16, 2008 at 1:50 AM, dav <[EMAIL PROTECTED]> wrote:
> Hi,
>
>  I have question about \0 character with DOM :
>
>  <?php
>  $cdata = 'foo' . "\0" . 'bar';
>
>  $dom = new DOMDocument('1.0', 'utf-8');
>  $dom->formatOutput = true;
>
>  $container = $dom->createElement('root');
>         $blob = $dom->createElement('blob');
>
>                 $blob->appendChild($dom->createCDATASection($cdata));
>
>         $container->appendChild($blob);
>  $dom->appendChild($container);
>
>  echo '<pre>' . htmlentities($dom->saveXML());
>
>  /*
>  Result :
>
>  <?xml version="1.0" encoding="utf-8"?>
>  <root>
>   <blob><![CDATA[foo]]></blob>
>  </root>
>  */
>  ?>
>
>
>  What to do with the character \0 ? encode this character to obtain : 
> <![CDATA[foo&00;bar]]> ? or skip the character with str_replace("\0", '', 
> $cdata)  ?
>
>  What is the best thing to do ? i like to conserve the \0 because is a blob 
> data
>
>  Jabber is how to transmit binary ?
>
>
>  Sorry for by bad english.
>
>
>  Thank you.
>
>  ----------------------------------------------------------------------
>  Free pop3 email with a spam filter.
>  http://www.bluebottle.com/tag/5
>
>
>  --
>  PHP General Mailing List (http://www.php.net/)
>  To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Maybe the entity "&#00;" works?

-- 
-Casey

--- End Message ---
--- Begin Message ---
dav wrote:
Hi,

I have question about \0 character with DOM :

<snip />

        
What to do with the character \0 ? encode this character to obtain : 
<![CDATA[foo&00;bar]]> ? or skip the character with str_replace("\0", '', 
$cdata)  ?


CDATA is raw data and why it doesnt get magically encoded. If you remove the character then you are altering the raw data - also not a good thing typically.

What is the best thing to do ? i like to conserve the \0 because is a blob data
        
Jabber is how to transmit binary ?

Never use CDATA sections. blob data should always be base64 encoded (or some other encoding). The data can then be transmitted in a regular element.

Note that it is possible that your blob data can contain the following sequence of characters "]]>" which would effectively terminate the CDATA block even though there really is more data.

Rob

--- End Message ---
--- Begin Message ---
Hi list!

__halt_compiler(). Does anyone use it?

I've used it obsessively in my past two "projects" to store data
(specifically CSV) in the PHP files. These two "projects" consisted of
only one file, and I didn't want to clutter everything and involve
databases and/or XML files.

Your thoughts?

-Casey

--- End Message ---
--- Begin Message ---
Hey All,

After searching I found this regex to remove img tags from a post, but running 
it is giving me an error, being a total noob with regex i have no idea what the 
heck is wrong.... heres the whole script as its tiny:

<?php

$html = " hello ".'<img src="/articles-blog/imgs/paul-fat.jpg" alt="" 
width="272" height="289" align="left">'. " Paul! ";

$html = 
preg_replace('</?img((\s+\w+(\s*=\s*(?:".*?"|\'.*?\'|[^\'">\s]+))?)+\s*|\s*)/?>',
 '', $html);

echo $html;
?>

Any help appreciated.

TIA,
Ryan

 
------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)




      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

--- End Message ---
--- Begin Message ---
Ryan A wrote:
Hey All,

After searching I found this regex to remove img tags from a post, but running 
it is giving me an error, being a total noob with regex i have no idea what the 
heck is wrong.... heres the whole script as its tiny:

<?php

$html = " hello ".'<img src="/articles-blog/imgs/paul-fat.jpg" alt="" width="272" height="289" 
align="left">'. " Paul! ";

$html = 
preg_replace('</?img((\s+\w+(\s*=\s*(?:".*?"|\'.*?\'|[^\'">\s]+))?)+\s*|\s*)/?>',
 '', $html);

echo $html;
?>

Any help appreciated.

TIA,
Ryan

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)




      
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs


why not a simple:
$html = preg_replace('#(<[/]?img.*>)#U', '', $html);
?

- Tul

--- End Message ---
--- Begin Message ---
M. Sokolewicz wrote:
Ryan A wrote:
Hey All,

After searching I found this regex to remove img tags from a post, but running it is giving me an error, being a total noob with regex i have no idea what the heck is wrong.... heres the whole script as its tiny:

<?php

$html = " hello ".'<img src="/articles-blog/imgs/paul-fat.jpg" alt="" width="272" height="289" align="left">'. " Paul! ";

$html = preg_replace('</?img((\s+\w+(\s*=\s*(?:".*?"|\'.*?\'|[^\'">\s]+))?)+\s*|\s*)/?>', '', $html);

echo $html;
?>

Any help appreciated.

TIA,
Ryan

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)




____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. http://www.yahoo.com/r/hs


why not a simple:
$html = preg_replace('#(<[/]?img.*>)#U', '', $html);
?

Wouldn't your example do this?

<p><img src="..." /><br /> some description</p>
    ^--catch from here to here ??-------------^

Would it not be better if the .* was [^>]+ instead. Wouldn't the .* catch an > even if it was like this?

Jim


- Tul



--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
M. Sokolewicz wrote:
Ryan A wrote:
Hey All,

After searching I found this regex to remove img tags from a post, but running it is giving me an error, being a total noob with regex i have no idea what the heck is wrong.... heres the whole script as its tiny:

<?php

$html = " hello ".'<img src="/articles-blog/imgs/paul-fat.jpg" alt="" width="272" height="289" align="left">'. " Paul! ";

$html = preg_replace('</?img((\s+\w+(\s*=\s*(?:".*?"|\'.*?\'|[^\'">\s]+))?)+\s*|\s*)/?>', '', $html);

echo $html;
?>

Any help appreciated.

TIA,
Ryan

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)




____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs


why not a simple:
$html = preg_replace('#(<[/]?img.*>)#U', '', $html);
?

Wouldn't your example do this?

<p><img src="..." /><br /> some description</p>
    ^--catch from here to here ??-------------^

Would it not be better if the .* was [^>]+ instead. Wouldn't the .* catch an > even if it was like this?

Jim


- Tul


The U modifier prevents that, it makes the expression ungreedy. So unless the OP has a tag with an > embedded in it, it should be fine.

- Tul

--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
M. Sokolewicz wrote:
Ryan A wrote:
Hey All,

After searching I found this regex to remove img tags from a post, but running it is giving me an error, being a total noob with regex i have no idea what the heck is wrong.... heres the whole script as its tiny:

<?php

$html = " hello ".'<img src="/articles-blog/imgs/paul-fat.jpg" alt="" width="272" height="289" align="left">'. " Paul! ";

$html = preg_replace('</?img((\s+\w+(\s*=\s*(?:".*?"|\'.*?\'|[^\'">\s]+))?)+\s*|\s*)/?>', '', $html);

echo $html;
?>

Any help appreciated.

TIA,
Ryan

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)




____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs


why not a simple:
$html = preg_replace('#(<[/]?img.*>)#U', '', $html);
?

Wouldn't your example do this?

<p><img src="..." /><br /> some description</p>
    ^--catch from here to here ??-------------^

Would it not be better if the .* was [^>]+ instead. Wouldn't the .* catch an > even if it was like this?

Jim


- Tul


The U modifier prevents that, it makes the expression ungreedy. So unless the OP has a tag with an > embedded in it, it should be fine.

- Tul

--- End Message ---
--- Begin Message ---
 Thanks guys!

This (From Tul/Sokolewicz):
$html = preg_replace('#(<[/]?img.*>)#U', '', $html);

worked perfectly! I'm just learning this stuff so its extremly hard for me... i 
have been messing around with PHP for years but rarely even dipped my toes into 
the REGEX part as I think it would be easier for me to learn greek :)

Now that thats over... can anybody recommend a good starting point to learn 
regex in baby steps?

Cheers!
R




      
____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping

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

I'm writing a simple httpd with php support via cgi/fastcgi. I tried several
ways to pass POST data to php-cgi (by writing to child process's stdin from
parent process), however, none of them worked

Here's the most simple not working example:

$ export CONTENT_LENGTH=4; export HTTP_METHOD=POST; echo 's=33' | php-cgi
test.php

and test.php has only one line:

<?php echo $_POST["s"]; ?>

Running it gave me:

X-Powered-By: PHP/5.2.3-1ubuntu6.3
Content-type: text/html

<br />
<b>Notice</b>:  Undefined index:  s in <b>/home/chen/temp/test.php</b> on
line <b>1</b><br />

Please help me figure out what's missing. Part of php-cgi's phpinfo() output
is attached, I will provide more if you need.

Thanks in advance,
Hui

=========phpinfo() output==========
_SERVER["TERM"]xterm
_SERVER["SHELL"]/bin/bash
_SERVER["SSH_TTY"]/dev/pts/1
_SERVER["CONTENT_LENG"]4
_SERVER["LD_LIBRARY_PATH"]/usr/local/lib
_SERVER["LS_COLORS"]no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.flac=01;35:*.mp3=01;35:*.mpc=01;35:*.ogg=01;35:*.wav=01;35:
_SERVER["LANG"]en_US.UTF-8
_SERVER["HISTCONTROL"]ignoredups
_SERVER["SHLVL"]1
_SERVER["CONTENT_LENGTH"]4
_SERVER["LESSOPEN"]| /usr/bin/lesspipe %s
_SERVER["HTTP_METHOD"]POST
_SERVER["CONTENT_TYPE"]application/x-www-f­orm-urlencoded
_SERVER["LESSCLOSE"]/usr/bin/lesspipe %s %s
_SERVER["_"]/usr/bin/php-cgi
_SERVER["PHP_SELF"]<i>no value</i>
_SERVER["REQUEST_TIME"]1205702297
_SERVER["argv"]</td><td class="v"><pre>Array
(
    [0] =&gt; phpinfo.php
)
</pre>

_SERVER["argc"]1
_ENV["TERM"]xterm
_ENV["SHELL"]/bin/bash
_ENV["SSH_TTY"]/dev/pts/1
_ENV["CONTENT_LENG"]4
_ENV["LD_LIBRARY_PATH"]/usr/local/lib
_ENV["LS_COLORS"]no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.flac=01;35:*.mp3=01;35:*.mpc=01;35:*.ogg=01;35:*.wav=01;35:
_ENV["LANG"]en_US.UTF-8
_ENV["HISTCONTROL"]ignoredups
_ENV["SHLVL"]1
_ENV["CONTENT_LENGTH"]4
_ENV["LESSOPEN"]| /usr/bin/lesspipe %s
_ENV["HTTP_METHOD"]POST
_ENV["CONTENT_TYPE"]application/x-www-f­orm-urlencoded
_ENV["LESSCLOSE"]/usr/bin/lesspipe %s %s
_ENV["_"]/usr/bin/php-cgi

--- End Message ---
--- Begin Message ---
I solved the problem myself.

Following command works:

export CONTENT_LENGTH=4; export REQUEST_METHOD=POST; export SCRIPT_FILENAME=
test.php ; export CONTENT_TYPE=application/x-www-form-urlencoded;  echo s=44
| php-cgi

output:

X-Powered-By: PHP/5.2.3-1ubuntu6.3
Content-type: text/html

44

a working C fork/exec example is also attached.

=========== test.c ===========

#include <unistd.h>
#include <stdio.h>
#include <string.h>

main()
{
    int outfd[2];
    int infd[2];
    int oldstdin, oldstdout;
    pipe(outfd); // Where the parent is going to write to
    pipe(infd); // From where parent is going to read
    if(!fork())
    {
        close(0);
        close(1);
        dup2(outfd[0], 0); // Make the read end of outfd pipe as stdin
        dup2(infd[1],1); // Make the write end of infd as stdout
        setenv("CONTENT_LENGTH", "4", 1);
        setenv("REQUEST_METHOD", "POST", 1);
        setenv("SCRIPT_FILENAME", "test.php", 1);
        setenv("CONTENT_TYPE", "application/x-www-form-urlencoded", 1);
        execl("/usr/bin/php-cgi","/usr/bin/php-cgi", NULL);
    }
    else
    {

        char output[1000];
        close(outfd[0]); // These are being used by the child
        write(outfd[1],"s=444", 5); // Write to child's stdin
        close(outfd[1]);
        close(infd[1]);
        output[read(infd[0],output,1000)] = 0; // Read from child's stdout
        printf("%s", output);
    }
}


On Sun, Mar 16, 2008 at 4:30 PM, Hui Chen <[EMAIL PROTECTED]> wrote:

> Hi,
>
> I'm writing a simple httpd with php support via cgi/fastcgi. I tried
> several ways to pass POST data to php-cgi (by writing to child process's
> stdin from parent process), however, none of them worked
>
> Here's the most simple not working example:
>
> $ export CONTENT_LENGTH=4; export HTTP_METHOD=POST; echo 's=33' | php-cgi
> test.php
>
> and test.php has only one line:
>
> <?php echo $_POST["s"]; ?>
>
> Running it gave me:
>
> X-Powered-By: PHP/5.2.3-1ubuntu6.3
> Content-type: text/html
>
> <br />
> <b>Notice</b>:  Undefined index:  s in <b>/home/chen/temp/test.php</b> on
> line <b>1</b><br />
>
> Please help me figure out what's missing. Part of php-cgi's phpinfo()
> output is attached, I will provide more if you need.
>
> Thanks in advance,
> Hui
>
> =========phpinfo() output==========
> _SERVER["TERM"]xterm
> _SERVER["SHELL"]/bin/bash
> _SERVER["SSH_TTY"]/dev/pts/1
> _SERVER["CONTENT_LENG"]4
> _SERVER["LD_LIBRARY_PATH"]/usr/local/lib
>
> _SERVER["LS_COLORS"]no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.flac=01;35:*.mp3=01;35:*.mpc=01;35:*.ogg=01;35:*.wav=01;35:
> _SERVER["LANG"]en_US.UTF-8
> _SERVER["HISTCONTROL"]ignoredups
> _SERVER["SHLVL"]1
> _SERVER["CONTENT_LENGTH"]4
> _SERVER["LESSOPEN"]| /usr/bin/lesspipe %s
> _SERVER["HTTP_METHOD"]POST
> _SERVER["CONTENT_TYPE"]application/x-www-f­orm-urlencoded
> _SERVER["LESSCLOSE"]/usr/bin/lesspipe %s %s
> _SERVER["_"]/usr/bin/php-cgi
> _SERVER["PHP_SELF"]<i>no value</i>
> _SERVER["REQUEST_TIME"]1205702297
> _SERVER["argv"]</td><td class="v"><pre>Array
> (
>     [0] =&gt; phpinfo.php
> )
> </pre>
>
> _SERVER["argc"]1
> _ENV["TERM"]xterm
> _ENV["SHELL"]/bin/bash
> _ENV["SSH_TTY"]/dev/pts/1
> _ENV["CONTENT_LENG"]4
> _ENV["LD_LIBRARY_PATH"]/usr/local/lib
>
> _ENV["LS_COLORS"]no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.flac=01;35:*.mp3=01;35:*.mpc=01;35:*.ogg=01;35:*.wav=01;35:
> _ENV["LANG"]en_US.UTF-8
> _ENV["HISTCONTROL"]ignoredups
> _ENV["SHLVL"]1
> _ENV["CONTENT_LENGTH"]4
> _ENV["LESSOPEN"]| /usr/bin/lesspipe %s
> _ENV["HTTP_METHOD"]POST
> _ENV["CONTENT_TYPE"]application/x-www-f­orm-urlencoded
> _ENV["LESSCLOSE"]/usr/bin/lesspipe %s %s
> _ENV["_"]/usr/bin/php-cgi
>
>

--- End Message ---
--- Begin Message ---
nihilism machine schreef:
I am trying to render an 8 pixel pixel font without anti aliasing to look crisp (silkscreen) in 8pt with gd. the font is huge and ugly:

<?php
// Set the content-type
header("Content-type: image/png");

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'silkscreen.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>


-- any ideas?

don't post twice.
use '8' instead of '20' for the fontsize.




--- End Message ---

Reply via email to