php-general Digest 9 Feb 2012 03:45:19 -0000 Issue 7681

Topics (messages 316554 through 316564):

Re: What's Your Favorite Design Pattern?
        316554 by: Tim Streater
        316558 by: Paul M Foster

sticky checkbox - strpos
        316555 by: Donovan Brooke
        316556 by: Donovan Brooke
        316557 by: Marc Guay

Re: Arrays: Comma at end?
        316559 by: Larry Garfield
        316560 by: Robert Cummings
        316561 by: Micky Hulse
        316562 by: Micky Hulse
        316563 by: Robert Cummings

Help!  Having trouble getting one XML field from this feed reliably
        316564 by: Rob Gould

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 07 Feb 2012 at 22:31, Paul M Foster <pa...@quillandmouse.com> wrote: 

> Design Patterns are Way Nifty Kewl patterns of code which are supposed
> to facilitate certain types of operations. (Was that sarcasm you
> detected? Yes it was.)
>
> For example, the Singleton pattern. Let's say you had a configuration
> class that held the configuration values for your application, and you
> wanted to make sure there was only one object of that class
> instantiated, no matter how many times it was called in your code. You'd
> arrange the code and call the class in a certain way to ensure that only
> one object of that class resulted. To make your configuration class a
> "singleton", you'd probably make the class have a *private* constructor
> (so no outside routine could call it), and then provide a method called
> get_instance() which tested for the existence of an object of that
> class. If such an instance was found, someone calling
> configuration::get_instance() would simply get the existing object
> returned to them. Otherwise, configuration::get_instance() would
> instantiate the class and then return the new object to the caller.
>
> As you can see, that's a peculiar way of setting up your code for a
> specific purpose. Other design patterns do other things and dictate
> setting up things in other ways.
>
> The definitive work on this (and where it first gained the most
> publicity) is a book called "Design Patterns" by four authors (Gamma,
> Helm, Johnson and Vlissides). It essentially contains a chapter about
> each (known at the time) design pattern and some pseudocode about how it
> might be constructed. I imagine the authors looked at a lot of code and
> discovered that programmers were coming up with code that, in each case
> was remarkably similar for solving certain types of programming
> problems. So they codified what that found and wrote a book about it.
>
> I have the book on my shelf, and it's decent technology, but you could
> spend your whole career and never use any of it, and get along just
> fine.

Mmmm. Well, at this point I feel underwhelmed - but its entirely possible that 
I'm missing something profound [1]. After looking at some of the reviews of the 
book you mention on Amazon, I might be inclined to get a simpler intro.

[1] In June 1982 (or was it '83?) I visited PARC with a small group from SLAC. 
We saw the Star or whatever it was, with bit-mapped display and mouse pointer. 
Whoosh !! (Well, to be fair, we'd gone along to look into XNS).

--
Cheers  --  Tim

--- End Message ---
--- Begin Message ---
On Wed, Feb 08, 2012 at 02:25:00PM +0000, Tim Streater wrote:


[snip]

> 
 Mmmm. Well, at this point I feel underwhelmed - but its entirely
> possible that I'm missing something profound [1]. 


Not really. 

> After looking at some of the reviews of the book you mention on
> Amazon, I might be inclined to get a simpler intro.

Um, yeah. It's very "meta". 

(That's what I love about "The C Programming Language". It's a little
over half an inch thick in paperback, explains the whole language
clearly and concisely, and has barely been revised since 1988. I'm not
sure you could ask for more in a technical book.)

> 
 [1] In June 1982 (or was it '83?) I visited PARC with a small group
> from SLAC. We saw the Star or whatever it was, with bit-mapped display
> and mouse pointer. Whoosh !! (Well, to be fair, we'd gone along to
> look into XNS).
 

I remember working for Xerox (copy center employee) around that time,
and seeing all kinds of talk in the company materials about *Ethernet*.
They explained the basic protocol and compared it to token ring, and I
just thought, "Hmm, yes, that seems like a pretty clever way to go about
networking."

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

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


if (!strpos($t_product,$t_p)) {print "checked";}

Would strpos be munged if $t_p contains commas?.. ie ",234,"

Thanks,
Donovan


--
D Brooke

--- End Message ---
--- Begin Message ---
Donovan Brooke wrote:
if (!strpos($t_product,$t_p)) {print "checked";}


Nevermind.. bad syntax I guess.. this works:

(strpos($t_product,$t_p) !== false)

Donovan


--
D Brooke

--- End Message ---
--- Begin Message ---
>> if (!strpos($t_product,$t_p)) {print "checked";}

It could have something to do with the function returning 0 because
it's finding the comma in the 0 index, but it's not really false, it's
still finding the string.  I've run into a similar problem before...

Marc

--- End Message ---
--- Begin Message ---
On 2/7/12 1:50 PM, Micky Hulse wrote:
Was there ever a time when having a comma at the end of the last array
element was not acceptable in PHP?

I just did a few quick tests:

<https://gist.github.com/1761490>

... and it looks like having that comma ain't no big deal.

I can't believe that I always thought that having the trailing comma
was a no-no in PHP (maybe I picked that up from my C++ classes in
college? I just don't remember where I picked up this (bad) habit).

I would prefer to have the trailing comma... I just can't believe I
have avoided using it for all these years.

Thanks!
Micky

Drupal's coding standards encourage the extra trailing comma on multi-line arrays, for all the readability and editability benefits that others have mentioned. We have for years. Cool stuff. :-)

--Larry Garfield

--- End Message ---
--- Begin Message ---
On 12-02-07 02:50 PM, Micky Hulse wrote:
Was there ever a time when having a comma at the end of the last array
element was not acceptable in PHP?

I just did a few quick tests:

<https://gist.github.com/1761490>

... and it looks like having that comma ain't no big deal.

I can't believe that I always thought that having the trailing comma
was a no-no in PHP (maybe I picked that up from my C++ classes in
college? I just don't remember where I picked up this (bad) habit).

I would prefer to have the trailing comma... I just can't believe I
have avoided using it for all these years.

JavaScript in Internet Crapsplorer spanks you on the bottom every time you have a trailing comma in a JS array. That may be where you picked up the aversion.

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.

--- End Message ---
--- Begin Message ---
On Wed, Feb 8, 2012 at 9:58 AM, Larry Garfield <la...@garfieldtech.com> wrote:
> Drupal's coding standards encourage the extra trailing comma on multi-line
> arrays, for all the readability and editability benefits that others have
> mentioned.  We have for years.  Cool stuff. :-)

Yah, I love that syntax guideline/rule in Python (tuples and other
things). I will definitely start doing this in PHP for arrays.

I am just surprised that there wasn't an older version of PHP that did
not allow this... I must have picked up this habit via my JS coding
knowledge. :D

Thanks again all!

Cheers,
Micky

--- End Message ---
--- Begin Message ---
On Wed, Feb 8, 2012 at 10:08 AM, Robert Cummings <rob...@interjinn.com> wrote:
> JavaScript in Internet Crapsplorer spanks you on the bottom every time you
> have a trailing comma in a JS array. That may be where you picked up the
> aversion.

On Wed, Feb 8, 2012 at 10:10 AM, Micky Hulse <rgmi...@gmail.com> wrote:
> I am just surprised that there wasn't an older version of PHP that did
> not allow this... I must have picked up this habit via my JS coding
> knowledge. :D

Jinx! You owe me a Coke!!! :)

--- End Message ---
--- Begin Message ---
On 12-02-08 01:12 PM, Micky Hulse wrote:
On Wed, Feb 8, 2012 at 10:08 AM, Robert Cummings<rob...@interjinn.com>  wrote:
JavaScript in Internet Crapsplorer spanks you on the bottom every time you
have a trailing comma in a JS array. That may be where you picked up the
aversion.

On Wed, Feb 8, 2012 at 10:10 AM, Micky Hulse<rgmi...@gmail.com>  wrote:
I am just surprised that there wasn't an older version of PHP that did
not allow this... I must have picked up this habit via my JS coding
knowledge. :D

Jinx! You owe me a Coke!!! :)

The timestamps above clearly show I was first ;)

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.

--- End Message ---
--- Begin Message ---
Can anyone tell me what I'm doing wrong here?  I'm trying to get the 
VASTAdTagURI field from the XML data at this url:

http://afe.specificclick.net/?l=32259&t=x&rnd=123456




Here's my code.  (below).  It works maybe 30% of the time, but most of the time 
it just returns nothing from that field.  Yet when I go to the above url in 
Firefox, I always see the data.  This is very strange.





// Lets get the ad!

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://afe.specificclick.net/?l=32259&t=x&rnd=123456');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

$vastdata = new SimpleXMLElement($buffer);

$vasturi = $vastdata->Ad->Wrapper->VASTAdTagURI;

echo "If the script works, vasturi = " . $vasturi;

echo "<br><br><br>";

print_r($vastdata);







--- End Message ---

Reply via email to