php-general Digest 3 May 2009 02:55:35 -0000 Issue 6100

Topics (messages 292217 through 292229):

Re: Static and/or Dynamic site scraping using PHP
        292217 by: Lenin
        292218 by: Lenin
        292219 by: Paul M Foster

Re: how to enable ttf support in php 5.2.9
        292220 by: Jim Lucas

Re: PHP6 return by reference deprecation
        292221 by: Larry Garfield
        292222 by: Colin Guthrie
        292223 by: Larry Garfield
        292224 by: Robert Cummings
        292229 by: Raymond Irving

Paypal and Php
        292225 by: Matthieu
        292226 by: Colin Guthrie

Re: object literals
        292227 by: Tom Worster

Dynamically Rename Images
        292228 by: Andrew Hucks

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 ---
I thought I would get some more experts giving me more insight about the
methods of scraping.

I want to grab the body content of pages say of Wordpress but not through
RSS. I would assume the pages are static only. And try to scrape the  body
content but avoiding  sidebar, footer, header etc.

I tried with the DOM and its fun. But just wanting to know some expert
experience on specific to my problem.

Thanks in advance.

--- End Message ---
--- Begin Message ---
On Sat, May 2, 2009 at 10:01 PM,
<[email protected]>wrote:

> Je suis actuellement absent du bureau aussi !!!!<br><br>TEST !!!!!
>
> I dont get it why I get this automated mail everytime I send message to
this thread.  :-/

--- End Message ---
--- Begin Message ---
On Sat, May 02, 2009 at 10:40:04PM +0600, Lenin wrote:

> On Sat, May 2, 2009 at 10:01 PM,
> <[email protected]>wrote:
> 
> > Je suis actuellement absent du bureau aussi !!!!<br><br>TEST !!!!!
> >
> > I dont get it why I get this automated mail everytime I send message to
> this thread.  :-/

My French is rusty, but it looks like it says something like "I'm out of
the office". So it would appear this <ahem> person has an autoreply
going.

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
PJ wrote:
Is there a module to be activated or what has to be installed to have
ttf support in php?
My port on FreeBSD does not have an option for ttf support under make
config .
I'm trying to learn & understand the following:
In file1 : <img src="button.php?s=36&text=PHP+is+Cool" />
In file2 (button.php)- originally php3 :
<?php
  Header("Content-type: image/gif");
  if(!isset($s)) $s=11;

The above should be:

if ( empty($_GET['s']) ) {
        $s = 11;
} else {
        $s = (int)$_GET['s'];
}

  $size = imagettfbbox($s,0,"times.ttf",$text);

and this should be

$text = '';
if ( !empty($_GET['text']) )
        $text = your_custom_input_cleaner_function($_GET['text']);

$size = imagettfbbox($s,0,"times.ttf",$text);

  $dx = abs($size[2]-$size[0]);
  $dy = abs($size[5]-$size[3]);
  $xpad=9;
  $ypad=9;
  $im = imagecreate($dx+$xpad,$dy+$ypad);
  $blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);
  $black = ImageColorAllocate($im, 0,0,0);
  $white = ImageColorAllocate($im, 255,255,255);
  ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
  ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white);
  ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black,
"times.ttf", $text);
  ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white,
"times.ttf", $text);
  ImageGif($im);
  ImageDestroy($im);
?>
ONLY the above & nothing else. So far, all I get is a small blue square.
Replacing the $text with the text just gives a rectangle a bit wider.
gd is installed but ttf is not, so I figure that is the culprit.
But how is the text supposed to be assigned to $text from file1?
TIA




--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
On Saturday 02 May 2009 9:30:09 am Colin Guthrie wrote:
> 'Twas brillig, and Paul M Foster at 02/05/09 06:07 did gyre and gimble:
> > If this is going away, how do you return things by reference, so as to
> > ensure a single copy of something (yes, I know the singleton pattern can
> > be used; I do use it as well; it's more complicated)?
>
> You'll want to use the Singleton design pattern here.
>
> Let's say you're config object is a class.

That's well and good if the thing you want a single copy of is an object.  The 
way objects pass in PHP 5 makes singletons easy.  But I actually just 
developed a system for PHP 5.2 that includes a class that deliberately allows 
a caller to reach in and grab an internal array-based data structure for 
special cases.

class Foo {
  protected $internalConfig = array(...);

  public function &getConfig() {
    return $this->internalConfig;
  }
}

$foo = new Foo();
...
$config = &$foo->getConfig();
// Do stuff to $config that wouldn't make sense to do via methods.

So do I understand the OP correctly that is going to break with PHP 6 now?  I 
certainly hope not, as that would be incredibly short sighted and stupid.  
There are plenty of use cases for returning by reference besides making PHP 4 
objects behave correctly.

-- 
Larry Garfield
[email protected]

--- End Message ---
--- Begin Message ---
'Twas brillig, and Larry Garfield at 02/05/09 20:00 did gyre and gimble:
On Saturday 02 May 2009 9:30:09 am Colin Guthrie wrote:
'Twas brillig, and Paul M Foster at 02/05/09 06:07 did gyre and gimble:
If this is going away, how do you return things by reference, so as to
ensure a single copy of something (yes, I know the singleton pattern can
be used; I do use it as well; it's more complicated)?
You'll want to use the Singleton design pattern here.

Let's say you're config object is a class.

That's well and good if the thing you want a single copy of is an object. The way objects pass in PHP 5 makes singletons easy. But I actually just developed a system for PHP 5.2 that includes a class that deliberately allows a caller to reach in and grab an internal array-based data structure for special cases.

class Foo {
  protected $internalConfig = array(...);

  public function &getConfig() {
    return $this->internalConfig;
  }
}

$foo = new Foo();
...
$config = &$foo->getConfig();
// Do stuff to $config that wouldn't make sense to do via methods.

So do I understand the OP correctly that is going to break with PHP 6 now? I certainly hope not, as that would be incredibly short sighted and stupid. There are plenty of use cases for returning by reference besides making PHP 4 objects behave correctly.

Use ArrayObject rather than just array. e.g.

class Foo {
  protected $internalConfig;

  public function __construct() {
    $this->internalConfig = new ArrayObject(...);
  }

  public function getConfig() {
    return $this->internalConfig;
  }
}

http://www.php.net/manual/en/class.arrayobject.php

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---
--- Begin Message ---
On Saturday 02 May 2009 3:20:24 pm Colin Guthrie wrote:
> 'Twas brillig, and Larry Garfield at 02/05/09 20:00 did gyre and gimble:
> > On Saturday 02 May 2009 9:30:09 am Colin Guthrie wrote:
> >> 'Twas brillig, and Paul M Foster at 02/05/09 06:07 did gyre and gimble:
> >>> If this is going away, how do you return things by reference, so as to
> >>> ensure a single copy of something (yes, I know the singleton pattern
> >>> can be used; I do use it as well; it's more complicated)?
> >>
> >> You'll want to use the Singleton design pattern here.
> >>
> >> Let's say you're config object is a class.
> >
> > That's well and good if the thing you want a single copy of is an object.
> >  The way objects pass in PHP 5 makes singletons easy.  But I actually
> > just developed a system for PHP 5.2 that includes a class that
> > deliberately allows a caller to reach in and grab an internal array-based
> > data structure for special cases.
> >
> > class Foo {
> >   protected $internalConfig = array(...);
> >
> >   public function &getConfig() {
> >     return $this->internalConfig;
> >   }
> > }
> >
> > $foo = new Foo();
> > ...
> > $config = &$foo->getConfig();
> > // Do stuff to $config that wouldn't make sense to do via methods.
> >
> > So do I understand the OP correctly that is going to break with PHP 6
> > now?  I certainly hope not, as that would be incredibly short sighted and
> > stupid. There are plenty of use cases for returning by reference besides
> > making PHP 4 objects behave correctly.
>
> Use ArrayObject rather than just array. e.g.
>
> class Foo {
>    protected $internalConfig;
>
>    public function __construct() {
>      $this->internalConfig = new ArrayObject(...);
>    }
>
>    public function getConfig() {
>      return $this->internalConfig;
>    }
> }
>
> http://www.php.net/manual/en/class.arrayobject.php
>
> Col

If it were just a simple one level array, sure.  But it's not.  It's actually 
quite deep and complex.  (That's why exposing it is a better plan than just 
offering an accessor.)

ArrayAccess is also dramatically slower than regular arrays:
http://www.garfieldtech.com/blog/magic-benchmarks

So forcing everything through an object is still pointless and a performance 
loss.

-- 
Larry Garfield
[email protected]

--- End Message ---
--- Begin Message ---
On Sat, 2009-05-02 at 15:43 -0500, Larry Garfield wrote:
> On Saturday 02 May 2009 3:20:24 pm Colin Guthrie wrote:
> > 'Twas brillig, and Larry Garfield at 02/05/09 20:00 did gyre and gimble:
> > > On Saturday 02 May 2009 9:30:09 am Colin Guthrie wrote:
> > >> 'Twas brillig, and Paul M Foster at 02/05/09 06:07 did gyre and gimble:
> > >>> If this is going away, how do you return things by reference, so as to
> > >>> ensure a single copy of something (yes, I know the singleton pattern
> > >>> can be used; I do use it as well; it's more complicated)?
> > >>
> > >> You'll want to use the Singleton design pattern here.
> > >>
> > >> Let's say you're config object is a class.
> > >
> > > That's well and good if the thing you want a single copy of is an object.
> > >  The way objects pass in PHP 5 makes singletons easy.  But I actually
> > > just developed a system for PHP 5.2 that includes a class that
> > > deliberately allows a caller to reach in and grab an internal array-based
> > > data structure for special cases.
> > >
> > > class Foo {
> > >   protected $internalConfig = array(...);
> > >
> > >   public function &getConfig() {
> > >     return $this->internalConfig;
> > >   }
> > > }
> > >
> > > $foo = new Foo();
> > > ...
> > > $config = &$foo->getConfig();
> > > // Do stuff to $config that wouldn't make sense to do via methods.
> > >
> > > So do I understand the OP correctly that is going to break with PHP 6
> > > now?  I certainly hope not, as that would be incredibly short sighted and
> > > stupid. There are plenty of use cases for returning by reference besides
> > > making PHP 4 objects behave correctly.
> >
> > Use ArrayObject rather than just array. e.g.
> >
> > class Foo {
> >    protected $internalConfig;
> >
> >    public function __construct() {
> >      $this->internalConfig = new ArrayObject(...);
> >    }
> >
> >    public function getConfig() {
> >      return $this->internalConfig;
> >    }
> > }
> >
> > http://www.php.net/manual/en/class.arrayobject.php
> >
> > Col
> 
> If it were just a simple one level array, sure.  But it's not.  It's actually 
> quite deep and complex.  (That's why exposing it is a better plan than just 
> offering an accessor.)
> 
> ArrayAccess is also dramatically slower than regular arrays:
> http://www.garfieldtech.com/blog/magic-benchmarks
> 
> So forcing everything through an object is still pointless and a performance 
> loss.

I don't know if it's even the case that it's going to be removed. I just
went back and checked the link to the article that was posted and it was
written in 2005. many things have changed since then and the article
isn't very accurate anymore. For instance the goto operator was added to
PHP 5.3 (woot) yet the article indicates it was not going to be added in
PHP6. So obviously it's dated. I would check internals before getting
too concerned.

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


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

I don't think they should remove return by reference features from php6 at all.

__
Raymond Irving

--- On Sat, 5/2/09, Robert Cummings <[email protected]> wrote:

> I don't know if it's even the case that it's going to be
> removed. I just
> went back and checked the link to the article that was
> posted and it was
> written in 2005. many things have changed since then and
> the article
> isn't very accurate anymore. For instance the goto operator
> was added to
> PHP 5.3 (woot) yet the article indicates it was not going
> to be added in
> PHP6. So obviously it's dated. I would check internals
> before getting
> too concerned.
> 
> Cheers,
> Rob.
> -- 
> http://www.interjinn.com
> Application and Templating Framework for PHP
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

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

I'd like to know if somebody already configured a paypal account usin php and a mysql database. What are the major things to know when starting to code the php code?

I know it's quite a large question but I'd like to know the amount of time needed, or if I directly go through a drupal server.

Thanks for your help

Matthieu
--- End Message ---
--- Begin Message ---
'Twas brillig, and Matthieu at 03/05/09 00:01 did gyre and gimble:
Hello,

I'd like to know if somebody already configured a paypal account usin php and a mysql database. What are the major things to know when starting to code the php code?

I know it's quite a large question but I'd like to know the amount of time needed, or if I directly go through a drupal server.

Thanks for your help

There is a discussion going on right now about Zend_Payment and Zend_Payment_Gateway_Paypal over on the Zend Framework mailing list. You could perhaps use these classes to interact with PayPal?

Proposal and discussion page is here for the overall Zend_Payment concept:
http://framework.zend.com/wiki/display/ZFPROP/Zend_Payment+-+Vadim+Gabriel

But check the zend framework general mailing list archive for better information.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---
--- Begin Message ---
On 5/2/09 6:45 AM, "Robert Cummings" <[email protected]> wrote:

> It's not what I want, I'm not the original poster.

as op, i think i'm going to stick with the cast. but it's been an
interesting thread and i learned some useful things.


> Regardless though, it
> comes down to the preference of the developer. It can certainly be
> simpler to type:
> 
>     $obj->blah->bleh->bluh;
> 
> than to type:
> 
>     $obj['blah']['bleh']['blug'];

exactly. and i dislike typing

   "SELECT col FROM tab WHERE a=" . $a['blah'] . " AND ... "

or even

   "SELECT col FROM tab WHERE a={$a['blah']} AND ... "

when i could type 

   "SELECT col FROM tab WHERE a=$a->blah AND ... "

which is also easier to read.

i'm really lazy about typing. 



--- End Message ---
--- Begin Message ---
Is it possible to rename images dynamically?

Say that I had something like image1.png, and I don't want to rename
it on the server. I'm working on an image rotater for a forum that
doesn't allow anything but image files as signatures.

Here's my code so far:

<?php

//LolRotator

//add images. not too hard.
$images = array("image1.png", "image2.png", "image3.png");
//which one do we gets?
$show = rand(0, (count($images)-1));
//i r got u picture.
echo '<img src="'.$images[$show].'"/>';

?>

I used mod_rewrite, which makes it from image.php to image.png. But,
because the files aren't named image.png, it doesn't work. I need to
figure out somethign between lines 8 and 10 to change the file name to
image.png.

Is there a way to do this?

--- End Message ---

Reply via email to