Re: [PHP] Re: Function size

2012-06-03 Thread Tony Marston
tamouse mailing lists  wrote in message 
news:cahuc_t__sw-_yhrw4n4uqr-fa46+cebunzgehboaatrafla...@mail.gmail.com...


On Tue, May 29, 2012 at 2:52 AM, Tony Marston
t...@marston-home.demon.co.uk wrote:

On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:

 A rule of thumb is no more than 50 lines per
function, most much less. Back in the day when we didn't have nifty
gui screens and an 24 line terminals (yay green on black!), if a
function exceeded one printed page, it was deemed too long and marked
for refactoring.


I think the idea of setting an arbitrary limit on the number of lines 
that a

function should contain is quite ludicrous and something which I will
completely ignore. If a function requires a hundred or more lines then so 
be
it. The only reason to take a block of code and put it into its own 
function
is when that code is likely to be called more than once so that it 
conforms
to the DRY principle. If it is only ever used in one place then there is 
no

point.



You obviously haven't spent much time maintaining other people's code.


I have been maintaining other people's code, which have been written to many 
different standards of varying quality, for many years.



There is a point: if you are unfamiliar with code, wading through
screens and screens of a function to find things like block
beginning/ends makes for difficult time finding places where changes
need to be made.


I *never* have huge numbers of lines between a block beginning and end. Even 
if I did my IDE can quickly find the other end of the block for me.



If you will never have your code maintained by anyone else, or
collaborate with anyone else, feel free to do what you want.


My code has been available in an open source framework for over 6 years, and 
I have never received any complaints on the readability of my code, only 
compliments.




The problems I have with creating lots of small used-only-once functions 
is

as follows:
- you have to create a meaningful name for each function.


Yes, you do, which is also considered a hallmark of good design.

- all those functions should be arranged in alphabetical order within 
their

containing file - having them in a random sequence makes it difficult to
find the one you want.


Also correct; this is a key point in making sure your scripts are 
maintainable.


Ah-ha! So someone agrees with me on that point after all.


- when browsing through the code you have to keep jumping to another
function, and then returning to where you came from.

I don't know about you, but I would rather use the scroll wheel on my 
mouse

than keep jumping from one position in the file to another.


May I suggest an editor/IDE that lets you navigate to functions directly, 
then?


I am *NOT* going to change my IDE just to suit *YOUR* preferences.

Another problem I have encountered in the past with such an idea is that 
it

encourages a stupid programmer to decrease the number of lines of code by
compressing as many statements as possible into a single line, which then
makes the code less easy to read and understand. This is much worse than
having more than 20 lines in a function.


There are counterbalancing things as well. If the only aspect of one's
coding standards are make it fit on one screen then yes, you might
see someone idiotic enough to do that. However, a good set of coding
standards includes things which will prevent this, such as not
stacking code like that.

Whether a file contains 10 functions of 100 lines each, or 100 functions 
of
10 lines each, you still end up with 1000 lines of code. If you do not 
have

the mental capacity to deal with a 100-line function then you are in the
wrong job.


The rules of thumb for coding standards are for maintainability,
primarily, so throwing up strawmen to try to weasel out of an idea is
pretty specious.


I will only follow standards which have a genuine purpose and a genuine 
benefit. I will *NOT* follow any which I consider to be arbitrary, 
artificial and pointless. There is *NO* limit to the number of lines in a 
function/method, and there is *NO* limit on the number of methods within a 
class. The only thing that matters is that the code is readable and 
maintainable. If some functions overflow the current screen then LEARN TO 
USE THE MOUSE WHEEL! That is what is was invented for in the first place. I 
will *NOT* make my code more difficult to read by creating a huge number of 
artificially small functions.



If you do not care about how much time it takes to fix defects in
other people's code, then I hope you remain a solitary programmer and
don't expect anyone else to use your code, otherwise, you are in the
wrong job.


I *DO* care, which is why I write code which is readable and maintainable.

--
Tony Marston

http://www.tonymarston.net
http://www.radicore.org 



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



Re: [PHP] Re: Function size

2012-06-03 Thread Tim Streater
On 03 Jun 2012 at 10:02, Tony Marston tonymars...@hotmail.com wrote: 

 tamouse mailing lists  wrote in message
 news:cahuc_t__sw-_yhrw4n4uqr-fa46+cebunzgehboaatrafla...@mail.gmail.com...

 There is a point: if you are unfamiliar with code, wading through
 screens and screens of a function to find things like block
 beginning/ends makes for difficult time finding places where changes
 need to be made.

 I *never* have huge numbers of lines between a block beginning and end. Even
 if I did my IDE can quickly find the other end of the block for me.

E.g. TextWrangler does this easily enough: just double-click immediately after 
an opening brace, and everything is highlighted to the closing brace.

 - all those functions should be arranged in alphabetical order within
 their containing file - having them in a random sequence makes it
 difficult to find the one you want.

 Also correct; this is a key point in making sure your scripts are
 maintainable.

 Ah-ha! So someone agrees with me on that point after all.

+1

 - when browsing through the code you have to keep jumping to another
 function, and then returning to where you came from.

 I don't know about you, but I would rather use the scroll wheel on my
 mouse
 than keep jumping from one position in the file to another.

 May I suggest an editor/IDE that lets you navigate to functions directly,
 then?

 I am *NOT* going to change my IDE just to suit *YOUR* preferences.

TW provided a popup list of your functions. It still helps to have them in 
alpha order though, for ease of navigation in the popup list.

[snip arguments]

I write functions to do specific things. E.g. I have a function (actually in 
JavaScript) called switchTab() which switches from one user view to another. 
It's just over 200 lines long and is mostly a giant case statement - and it's 
already loaded with function calls. I suppose I could break it up into five 
separate functions, more or less one for each case value, but then I'd have 
lots of unimportant local variables to pass around as argument values, and, 
what's worse, lots of unimportant functions cluttering the place up.

--
Cheers  --  Tim

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

Re: [PHP] Re: Function size

2012-06-03 Thread Tony Marston

Tim Streater  wrote in message news:d0.7c.45755.25a3b...@pb1.pair.com...


On 03 Jun 2012 at 10:02, Tony Marston tonymars...@hotmail.com wrote:


tamouse mailing lists  wrote in message
news:cahuc_t__sw-_yhrw4n4uqr-fa46+cebunzgehboaatrafla...@mail.gmail.com...



There is a point: if you are unfamiliar with code, wading through
screens and screens of a function to find things like block
beginning/ends makes for difficult time finding places where changes
need to be made.


I *never* have huge numbers of lines between a block beginning and end. 
Even

if I did my IDE can quickly find the other end of the block for me.


E.g. TextWrangler does this easily enough: just double-click immediately 
after an opening brace, and everything is highlighted to the closing brace.



- all those functions should be arranged in alphabetical order within
their containing file - having them in a random sequence makes it
difficult to find the one you want.


Also correct; this is a key point in making sure your scripts are
maintainable.


Ah-ha! So someone agrees with me on that point after all.


+1


- when browsing through the code you have to keep jumping to another
function, and then returning to where you came from.

I don't know about you, but I would rather use the scroll wheel on my
mouse
than keep jumping from one position in the file to another.


May I suggest an editor/IDE that lets you navigate to functions 
directly,

then?


I am *NOT* going to change my IDE just to suit *YOUR* preferences.


TW provided a popup list of your functions. It still helps to have them in 
alpha order though, for ease of navigation in the popup list.


[snip arguments]

I write functions to do specific things. E.g. I have a function (actually 
in JavaScript) called switchTab() which switches from one user view to 
another. It's just over 200 lines long and is mostly a giant case 
statement - and it's already loaded with function calls. I suppose I could 
break it up into five separate functions, more or less one for each case 
value, but then I'd have lots of unimportant local variables to pass around 
as argument values, and, what's worse, lots of unimportant functions 
cluttering the place up.


Exactly! That's one good reason *NOT* to break up a large function into 
artificially small pieces. You generate a lot of useless code just to handle 
the small pieces, and wading through lots of useless code makes it less 
readable. In my opinion it takes less effort to use the scroll wheel on my 
mouse than it does to jump/return from different parts of the file. There 
are times when it makes sense to split a large function into smaller pieces, 
but I'm afraid that doing so for no other reason than to satisfy someone's 
personal line limit is just not good enough.


--
Tony Marston

http://www.tonymarston.net
http://www.radicore.org 



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



Re: [PHP] Using default argument values in the middle of the argument list

2012-06-03 Thread oliver gondža

On Sat, 02 Jun 2012 21:35:28 +0200, Matijn Woudt tijn...@gmail.com wrote:


It does not state it works only at the end of the list, it states that
it only makes sense to use it at the end of the argument list to be
able to call the function with less arguments. In case you want to use
it as suggested in [2], you can use it anywhere. You can rely on that
in any PHP version from 5 upwards, just because version 4 doesn't
support type hinting at all.

- Matijn

[2] http://php.net/manual/en/language.oop5.typehinting.php


Wow that's great. Just to be sure are we talking about functions it's  
default arguments precedes its non-default arguments:


function f ( Classname $a = null, Classname $b ) { ... }

I believe it should be clearly stated in documentation that it is possible  
for several reasons.


- I have never thought of using type hints and default arguments this way  
until I found it by accident.
- I have never seen someone else using it (I've just search installed PEAR  
packages, codebase of Symphony2, Zend2 and several others and found *one*  
function definition taking advantage of this*).
- As far as i know other languages that support default argument values  
allow specifying default arguments only for rightmost function arguments.
- As far as i know the only part of documentation that illustrates  
function declarations having default argument preceding non-default  
arguments is the one titled: Incorrect usage of default function  
arguments in http://www.php.net/manual/en/functions.arguments.php.


I just wanted to be sure this is haw it is supposed to be used.

* DibiColumnInfo::__construct(IDibiReflector $reflector = NULL, array  
$info) in  
https://github.com/dg/dibi/blob/master/dibi/libs/DibiDatabaseInfo.php#L458


-- Oliver

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



Re: [PHP] cyberweaponry

2012-06-03 Thread Tedd Sperling
On May 31, 2012, at 7:45 PM, Ross McKay wrote:

 On Thu, 31 May 2012 13:21:07 -0400, Tedd Sperling wrote:
 
 [...]
 I watched a interview today where an security expert claimed that 
 the Flame Virus was written in a scripted language named lua 
 (http://www.lua.org/).
 
 That's surprising... I'm intrigued, can you supply a link?

No, there was no link. If I remember correctly, it was an interview done on Fox 
News.


 He said that this was unusual because typically such viruses are
 written in languages like Ruby-on-Rails and such.
 
 Um, really? I very much doubt that. AFAIK, most true viruses are written
 in a compiled language, and many trojans as well. RoR websites would
 definitely be a vulnerability target though...

Yeah, that's what I thought, but this guy was held out to be one of the 
foremost experts on cyber-warfare. So, I listened and asked.

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com



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



Re: [PHP] cyberweaponry

2012-06-03 Thread Daniel P. Brown
On Jun 3, 2012 12:05 PM, Tedd Sperling t...@sperling.com wrote:

 On May 31, 2012, at 7:45 PM, Ross McKay wrote:

  He said that this was unusual because typically such viruses are
  written in languages like Ruby-on-Rails and such.
 
  Um, really? I very much doubt that. AFAIK, most true viruses are written
  in a compiled language, and many trojans as well. RoR websites would
  definitely be a vulnerability target though...

 Yeah, that's what I thought, but this guy was held out to be one of the
foremost experts on cyber-warfare. So, I listened and asked.

Actually, that's not true anymore. Flame was indeed written in Lua (and
you can find the source if you look), and while that choice of language is
a bit surprising, since it's a gaming language, the choice of distributing
a script-based virus/worm is not unique. Remember, WSH viruses and worms,
though not as prevalent today, were some of the most widespread and
destructive forms of malware in history --- a la
Loveletter/Lovebug/ILOVEYOU.


Re: [PHP] Using default argument values in the middle of the argument list

2012-06-03 Thread Matijn Woudt
On Sun, Jun 3, 2012 at 4:48 PM, oliver gondža ogon...@gmail.com wrote:
 On Sat, 02 Jun 2012 21:35:28 +0200, Matijn Woudt tijn...@gmail.com wrote:

 It does not state it works only at the end of the list, it states that
 it only makes sense to use it at the end of the argument list to be
 able to call the function with less arguments. In case you want to use
 it as suggested in [2], you can use it anywhere. You can rely on that
 in any PHP version from 5 upwards, just because version 4 doesn't
 support type hinting at all.

 - Matijn

 [2] http://php.net/manual/en/language.oop5.typehinting.php


 Wow that's great. Just to be sure are we talking about functions it's
 default arguments precedes its non-default arguments:

 function f ( Classname $a = null, Classname $b ) { ... }

 I believe it should be clearly stated in documentation that it is possible
 for several reasons.

 - I have never thought of using type hints and default arguments this way
 until I found it by accident.
 - I have never seen someone else using it (I've just search installed PEAR
 packages, codebase of Symphony2, Zend2 and several others and found *one*
 function definition taking advantage of this*).
 - As far as i know other languages that support default argument values
 allow specifying default arguments only for rightmost function arguments.
 - As far as i know the only part of documentation that illustrates function
 declarations having default argument preceding non-default arguments is the
 one titled: Incorrect usage of default function arguments in
 http://www.php.net/manual/en/functions.arguments.php.

 I just wanted to be sure this is haw it is supposed to be used.

 * DibiColumnInfo::__construct(IDibiReflector $reflector = NULL, array $info)
 in
 https://github.com/dg/dibi/blob/master/dibi/libs/DibiDatabaseInfo.php#L458

 -- Oliver

Yes, we're talking about the same thing. I guess the reason that you
don't see arguments with default values before other arguments is
because they are only useful in combination with type hinting a class.
And, even when using it in this combination, most of us will probably
prefer the argument with the default value at the end, so we can omit
this parameter when calling the function. It seems to me you might be
thinking a little bit too much inside a Java box ;)

- Matijn

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



[PHP] disabled cookies

2012-06-03 Thread Al

Disabled cookies use to be a problem years ago.  What's your experience these 
days.

I need it for my session ID. As I read the docs, the old method of appending it 
to the URL is a security issue.


I can obviously save the ID in a temp file which can be read by all the pages 
needing it.


Al

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



Re: [PHP] disabled cookies

2012-06-03 Thread Ashley Sheridan


Al n...@ridersite.org wrote:

Disabled cookies use to be a problem years ago.  What's your experience
these days.

I need it for my session ID. As I read the docs, the old method of
appending it
to the URL is a security issue.

I can obviously save the ID in a temp file which can be read by all the
pages
needing it.

Al

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

There is a new law been passed in the UK that makes non-essential cookies 
opt-in only, so you must get permission in order to use them.

That said, session cookies are a bit of a grey area. If your site relies on 
them to function, then they're ok. If they're used purely for tracking, they 
need to be made opt-in. Everything between is, like I said, grey.

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

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



Re: [PHP] disabled cookies

2012-06-03 Thread Matijn Woudt
On Sun, Jun 3, 2012 at 11:21 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:


 Al n...@ridersite.org wrote:

Disabled cookies use to be a problem years ago.  What's your experience
these days.

I need it for my session ID. As I read the docs, the old method of
appending it
to the URL is a security issue.

I can obviously save the ID in a temp file which can be read by all the
pages
needing it.

Al

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

 There is a new law been passed in the UK that makes non-essential cookies 
 opt-in only, so you must get permission in order to use them.

 That said, session cookies are a bit of a grey area. If your site relies on 
 them to function, then they're ok. If they're used purely for tracking, they 
 need to be made opt-in. Everything between is, like I said, grey.

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


A little correction on the above: This law applies to the whole EU, not only UK.

- Matijn

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



Re: [PHP] disabled cookies

2012-06-03 Thread Ashley Sheridan


Matijn Woudt tijn...@gmail.com wrote:

On Sun, Jun 3, 2012 at 11:21 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:


 Al n...@ridersite.org wrote:

Disabled cookies use to be a problem years ago.  What's your
experience
these days.

I need it for my session ID. As I read the docs, the old method of
appending it
to the URL is a security issue.

I can obviously save the ID in a temp file which can be read by all
the
pages
needing it.

Al

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

 There is a new law been passed in the UK that makes non-essential
cookies opt-in only, so you must get permission in order to use them.

 That said, session cookies are a bit of a grey area. If your site
relies on them to function, then they're ok. If they're used purely for
tracking, they need to be made opt-in. Everything between is, like I
said, grey.

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


A little correction on the above: This law applies to the whole EU, not
only UK.

- Matijn

Oh, my bad!

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

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



Re: [PHP] disabled cookies

2012-06-03 Thread Matijn Woudt
On Sun, Jun 3, 2012 at 11:26 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Sun, Jun 3, 2012 at 11:21 PM, Ashley Sheridan
 a...@ashleysheridan.co.uk wrote:


 Al n...@ridersite.org wrote:

Disabled cookies use to be a problem years ago.  What's your experience
these days.

I need it for my session ID. As I read the docs, the old method of
appending it
to the URL is a security issue.

I can obviously save the ID in a temp file which can be read by all the
pages
needing it.

Al

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

 There is a new law been passed in the UK that makes non-essential cookies 
 opt-in only, so you must get permission in order to use them.

 That said, session cookies are a bit of a grey area. If your site relies on 
 them to function, then they're ok. If they're used purely for tracking, they 
 need to be made opt-in. Everything between is, like I said, grey.

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


 A little correction on the above: This law applies to the whole EU, not only 
 UK.

 - Matijn

BTW, There's a website [1] that has all the information and even a
tool for checking what your site does with cookies.

- Matijn

[1] http://www.cookielaw.org/

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



Re: [PHP] disabled cookies

2012-06-03 Thread Lester Caine

Matijn Woudt wrote:

BTW, There's a website [1] that has all the information and even a
tool for checking what your site does with cookies.

- Matijn

[1]http://www.cookielaw.org/


Which fails at the first security hurdle!
It requires Google Chrome, which is bigger black hole as far as my customers are 
concerned.


http://www.ico.gov.uk/for_organisations/privacy_and_electronic_communications/the_guide/cookies.aspx 
is perhaps the best guidance for UK users ... currently.


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



Re: [PHP] disabled cookies

2012-06-03 Thread Ashley Sheridan


Lester Caine les...@lsces.co.uk wrote:

Matijn Woudt wrote:
 BTW, There's a website [1] that has all the information and even a
 tool for checking what your site does with cookies.

 - Matijn

 [1]http://www.cookielaw.org/

Which fails at the first security hurdle!
It requires Google Chrome, which is bigger black hole as far as my
customers are
concerned.

http://www.ico.gov.uk/for_organisations/privacy_and_electronic_communications/the_guide/cookies.aspx

is perhaps the best guidance for UK users ... currently.

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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

How is Google Chrome a bigger security risk than the other popular browsers, Fx 
and IE?

I was under the impression it was more secure than either of those.

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

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



Re: [PHP] disabled cookies

2012-06-03 Thread Lester Caine

Ashley Sheridan wrote:

How is Google Chrome a bigger security risk than the other popular browsers, Fx 
and IE?

I was under the impression it was more secure than either of those.


License Conditions ... They may have removed the original landgrab section, but 
there is still a potential for Google to gather private information and this is 
an unacceptable risk when dealing with customers who deal with sensitive private 
data.


In addition, intrusive advertising has no place in public service systems anyway 
... Google maps and the like are similarly inappropriate since using them allows 
Google to track material that IS also sensitive. It is THIS tracking that the 
'cookie law' was supposed to address, but the problem sites are not even covered 
by it ... WE are if we link to uncontrolled sites and services.


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



Re: [PHP] disabled cookies

2012-06-03 Thread Ashley Sheridan


Lester Caine les...@lsces.co.uk wrote:

Ashley Sheridan wrote:
 How is Google Chrome a bigger security risk than the other popular
browsers, Fx and IE?

 I was under the impression it was more secure than either of those.

License Conditions ... They may have removed the original landgrab
section, but
there is still a potential for Google to gather private information and
this is
an unacceptable risk when dealing with customers who deal with
sensitive private
data.

In addition, intrusive advertising has no place in public service
systems anyway
... Google maps and the like are similarly inappropriate since using
them allows
Google to track material that IS also sensitive. It is THIS tracking
that the
'cookie law' was supposed to address, but the problem sites are not
even covered
by it ... WE are if we link to uncontrolled sites and services.

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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

Ok, but don't confuse the browser with the services Google offers. The two are 
very separate, and its confusing to mention the services in an argument about 
the browser.

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

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



[PHP] help with preg_match

2012-06-03 Thread Chris Purves

Hello,

I am trying to use preg_match to match something from an html file. 
Within the html file is some text that looks like:


spanSomething, something end/span

I know that the text ends 'end', but I don't know what the Something, 
something is.  I am using preg_match as follows:


preg_match('/[^]*end/',$curl_response,$matches);

I want to match 'end' and everything before it that is not ''.

The problem appears to be with the ''.  I have tried escaping (\), but 
it didn't make a difference.  The php script hangs when it tries to run 
this function.



--
Chris Purves

There's a time to think, and a time to act. And this, gentlemen, is no 
time to think. - Sheriff Bud B. Boomer


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



Re: [PHP] help with preg_match

2012-06-03 Thread Robert Williams
On Jun 3, 2012, at 17:28, Chris Purves ch...@northfolk.ca wrote:

 I know that the text ends 'end', but I don't know what the Something,
 something is.  I am using preg_match as follows:

 preg_match('/[^]*end/',$curl_response,$matches);

 I want to match 'end' and everything before it that is not ''.

You need to match something at the beginning. Try this:

preg_match('/([^]*end)/', $curl_response, $matches);

Assuming a match, you can then look to $matches[1] for your content.


--
Bob Williams

Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



RE: [PHP] help with preg_match

2012-06-03 Thread admin


-Original Message-
From: Chris Purves [mailto:ch...@northfolk.ca] 
Sent: Sunday, June 03, 2012 8:26 PM
To: php-general General
Subject: [PHP] help with preg_match

Hello,

I am trying to use preg_match to match something from an html file. 
Within the html file is some text that looks like:

spanSomething, something end/span

I know that the text ends 'end', but I don't know what the Something,
something is.  I am using preg_match as follows:

preg_match('/[^]*end/',$curl_response,$matches);

I want to match 'end' and everything before it that is not ''.

The problem appears to be with the ''.  I have tried escaping (\), but it
didn't make a difference.  The php script hangs when it tries to run this
function.


--
Chris Purves

There's a time to think, and a time to act. And this, gentlemen, is no time
to think. - Sheriff Bud B. Boomer

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

You could try this

preg_match_all('/(span[^]**)(.*)(/span[^]*)/is',$curl_response,$matc
hes);
print_r($matches);



Rick


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