php-general Digest 10 Jul 2009 15:39:29 -0000 Issue 6222

Topics (messages 295124 through 295146):

DOMDocument saveHTML() configurable?
        295124 by: Michael A. Peters

HTTP headers and include()
        295125 by: James Colannino
        295126 by: Eddie Drapkin
        295127 by: Michael A. Peters
        295129 by: James Colannino
        295131 by: kranthi
        295138 by: tedd
        295142 by: Michael A. Peters

open source event calendar
        295128 by: Joey
        295130 by: kranthi
        295136 by: Daniel Brown
        295139 by: tedd

Re: Obeying the rules (was Simple login form with cookies)
        295132 by: Arno Kuhl
        295135 by: abdulazeez alugo

Re: SESSION variables: How much is too much?
        295133 by: kranthi
        295137 by: tedd

Re: mysterious " f " character appearing. Why??
        295134 by: kranthi

Re: PHP script for detecting pattern sequences?
        295140 by: Isaac Dover
        295143 by: Andrew Ballard
        295145 by: Isaac Dover

Error Trapping
        295141 by: Floyd Resler
        295144 by: Eddie Drapkin
        295146 by: Floyd Resler

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 --- The $dom->saveHTML() function does a pretty good job of knowing what tags are not closed - IE it does <br>, <meta>, <param>, etc. correctly.

Is there a way to add a tag without children to it's database?

Specifically I'm talking about the new <source> tag from HTML 5 that is being used to embed ogg/mp4 audio and video files.

Put it in a dom document object and spit it out with saveHTML() and you get <source src="foo.ogg" type="video/ogg"></source> which is harmless but technically incorrect.

I know html tidy allows you to define new childless nodes and sending the output through tidy will then fix it, but I can't seem to find a way to to it with DOMDocument so that you don't need to send it through tidy before sending to the client.
--- End Message ---
--- Begin Message ---
Hey everyone,

I've been hard at work on a new web application, and discovered
something that I would never have seen coming.  I was noticing that when
I called session_start() after a few lines of includes, I was getting
complaints because the HTTP headers had already been sent out.  Then,
after putting session_start() above the include lines, suddenly
everything was working fine.

The files that were included were nothing more than functions; there was
no code executing that I could tell up to the point of the call to
session_start().

I was just wondering if anybody on the list knows why HTTP headers were
being sent out by my includes.  I'm sure there's a good reason.  I'm
just very curious :)

Thanks very much in advance.

James

--- End Message ---
--- Begin Message ---
On Fri, Jul 10, 2009 at 1:21 AM, James Colannino<ja...@colannino.org> wrote:
> Hey everyone,
>
> I've been hard at work on a new web application, and discovered
> something that I would never have seen coming.  I was noticing that when
> I called session_start() after a few lines of includes, I was getting
> complaints because the HTTP headers had already been sent out.  Then,
> after putting session_start() above the include lines, suddenly
> everything was working fine.
>
> The files that were included were nothing more than functions; there was
> no code executing that I could tell up to the point of the call to
> session_start().
>
> I was just wondering if anybody on the list knows why HTTP headers were
> being sent out by my includes.  I'm sure there's a good reason.  I'm
> just very curious :)
>
> Thanks very much in advance.
>
> James
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

HTTP headers are sent and finalized after the first bit of output.   I
had the same problem before and it turned out to be because I had a
close tag "?>" at the end of a file followed by some whitespace.  The
solution was to remove the ?> from the end of all the files and I
haven't closed an entire file since.  Perhaps that might be it?

--Eddie

--- End Message ---
--- Begin Message ---
James Colannino wrote:
Hey everyone,

I've been hard at work on a new web application, and discovered
something that I would never have seen coming.  I was noticing that when
I called session_start() after a few lines of includes, I was getting
complaints because the HTTP headers had already been sent out.  Then,
after putting session_start() above the include lines, suddenly
everything was working fine.

The files that were included were nothing more than functions; there was
no code executing that I could tell up to the point of the call to
session_start().

I was just wondering if anybody on the list knows why HTTP headers were
being sent out by my includes.  I'm sure there's a good reason.  I'm
just very curious :)

Thanks very much in advance.

James


White space can cause this - make sure your code has <?php as the very top and ?> at the very bottom, or the white space may trigger the web server to send a header and the white space as data before the cookie for session_start() is sent.
--- End Message ---
--- Begin Message ---
Eddie Drapkin wrote:

> HTTP headers are sent and finalized after the first bit of output.   I
> had the same problem before and it turned out to be because I had a
> close tag "?>" at the end of a file followed by some whitespace.  The
> solution was to remove the ?> from the end of all the files and I
> haven't closed an entire file since.  Perhaps that might be it?

Hmm...  In fact, I did close all my include files with the ?> tag, and
per Michael's observation in another response, there is a line of
whitespace after the closing tag in my include files.

I tried getting rid of the trailing whitespace, and removed the closing
tags.  Unfortunately, even after that, when I place my include files
before session_start, I get the same problem.  There's no leading
whitespace before the starting <?php tag, so I'm still a little at a loss.

It's not too big of a deal though; I simply placed my include files
after the call to session_start().  That seems to solve the problem.

James

--- End Message ---
--- Begin Message ---
a single line break after the closing ?> will not cause this problem. PHP
interpreter will neglect a single line break after ?> a good debugger like
xdebug will be helpful in this case. u can also see the source code of the
file to locate the output. any thing before php warning is the output before
session_start()

--- End Message ---
--- Begin Message ---
At 12:24 AM -0700 7/10/09, James Colannino wrote:
Eddie Drapkin wrote:

 HTTP headers are sent and finalized after the first bit of output.   I
 had the same problem before and it turned out to be because I had a
 close tag "?>" at the end of a file followed by some whitespace.  The
 solution was to remove the ?> from the end of all the files and I
 haven't closed an entire file since.  Perhaps that might be it?

Hmm...  In fact, I did close all my include files with the ?> tag, and
per Michael's observation in another response, there is a line of
whitespace after the closing tag in my include files.

I tried getting rid of the trailing whitespace, and removed the closing
tags.  Unfortunately, even after that, when I place my include files
before session_start, I get the same problem.  There's no leading
whitespace before the starting <?php tag, so I'm still a little at a loss.

It's not too big of a deal though; I simply placed my include files
after the call to session_start().  That seems to solve the problem.

James


James:

As I understand things, that's the way it is supposed to work -- you always start a session page off with session_start() as your first statement.

I've had some pages complain that a session has already been started and in that case, I check to see if a session ID is set and it not, then do a session_start().

But, as a matter of habit, I always make session_start() my first line of code.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
tedd wrote:
At 12:24 AM -0700 7/10/09, James Colannino wrote:
Eddie Drapkin wrote:

 HTTP headers are sent and finalized after the first bit of output.   I
 had the same problem before and it turned out to be because I had a
 close tag "?>" at the end of a file followed by some whitespace.  The
 solution was to remove the ?> from the end of all the files and I
 haven't closed an entire file since.  Perhaps that might be it?

Hmm...  In fact, I did close all my include files with the ?> tag, and
per Michael's observation in another response, there is a line of
whitespace after the closing tag in my include files.

I tried getting rid of the trailing whitespace, and removed the closing
tags.  Unfortunately, even after that, when I place my include files
before session_start, I get the same problem.  There's no leading
whitespace before the starting <?php tag, so I'm still a little at a loss.

It's not too big of a deal though; I simply placed my include files
after the call to session_start().  That seems to solve the problem.

James


James:

As I understand things, that's the way it is supposed to work -- you always start a session page off with session_start() as your first statement.

I've had some pages complain that a session has already been started and in that case, I check to see if a session ID is set and it not, then do a session_start().

But, as a matter of habit, I always make session_start() my first line of code.

Cheers,

tedd


If the included file has

<?php
somefunc() {
  }
?>

<?php
somefunc() {
  }
?>

that will also cause it.
Or maybe one of the include files includes a file (IE db connection script) that has white space.
--- End Message ---
--- Begin Message ---
Hello All!

 

Does anyone know of a good open source calendar app?

Hopefully one that has ongoing development etc.

 

( sorry asked this before, but can't find a web list to search for the
previous results, php.net has a list that is not searchable )

 

 

Thanks!

 

 

 

 

 


--- End Message ---
--- Begin Message ---
that depends upon your need.embedding google calendar is best for starters

--- End Message ---
--- Begin Message ---
On Fri, Jul 10, 2009 at 03:13, Joey<j...@web56.net> wrote:
> Hello All!
>
> Does anyone know of a good open source calendar app?
>
> Hopefully one that has ongoing development etc.
>
> ( sorry asked this before, but can't find a web list to search for the
> previous results, php.net has a list that is not searchable )

    Did you try Google?  Did you then try searching Google for
'mailing list archives'?  I had no problem finding a few thousand
results.

    http://www.gmane.org/
    http://www.marc.info/
    http://news.php.net/
    http://google.com/search?q=open+source+php+calendar+script

-- 
</Daniel P. Brown>
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

--- End Message ---
--- Begin Message ---
At 3:13 AM -0400 7/10/09, Joey wrote:
Hello All!

Does anyone know of a good open source calendar app?

Hopefully one that has ongoing development etc.

( sorry asked this before, but can't find a web list to search for the
previous results, php.net has a list that is not searchable )

Joey:

Sure, try:

http://php-calendar.com

That's an on-going development -- in fact I added a little contribution last month.

Besides his demo, here it is working for me:

http://php1.net/my-php-calendar/

If you want something simpler, try this:

http://www.webbytedd.com/bbbb/tedd-php-calendar/

All the code is there. Use as you want.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
I'm sure those who've been on this list a while muttered "here we go
again..." when this thread started. Personally I think if there was a poll
about this the bell curve would have some on the left demanding we all top
post, many on the right of the curve demanding we all bottom post, and a
solid bulge in the middle representing the great unwashed "couldn't give a
damn" folks (and probably "couldn't give a damn" to enter the debate). On
the very few occasions I've had anything to contribute I've generally bottom
posted, mostly because I've seen this debate before and partly because I
think it's easier for some people, but I'd place myself in the middle of the
bell curve. I think most people on this list are more than smart enough to
quickly figure out the thread in a post regardless whether the previous
person top posted or not. Most of the regular responders bottom post which
makes up the bulk, but I think if you look at the variety of people who post
it's about 50/50, and most times it doesn't cause any problem at all. I
agree that rules are important, but some are more important than others, and
I think the top-posting rule is pretty low in the list of priorities, more a
useful guide than a rule. Things like personal attacks and attempted mail
spoofing are more important - both happened during the course of this thread
but hardly raised an eyebrow. I also agree that context plays a big part,
because once a thread starts getting complicated with many responses then
bottom posting definitely makes it easier to follow, but most threads don't
get to that stage. Just my 2c.

Cheers
Arno


--- End Message ---
--- Begin Message ---
> To: php-gene...@lists.php.net
> From: t...@marston-home.demon.co.uk
> Date: Thu, 9 Jul 2009 22:37:44 +0100
> Subject: Re: [PHP] Obeying the rules (was Simple login form with cookies)
> 
> 
> "Still Learnin'" <ssski...@gmail.com> wrote in message 
> news:4a565c73.8090...@gmail.com...
> > Tony Marston wrote:
> >
> >>> You've been told more than twice, it isn't an arbitrary rule. It isn't
> >>> a petty rule. It isn't about perfection.
> >>
> >> It is arbitrary. It is petty. It is about someone's idea of perfection.
> >
> > One of us clearly manifests a reality gap. How many people do you
> > have siding with your position, on this list?
> >
> >>> It's about clarity. So that the threaded archives are intelligible
> >>> instead of jumbled. So that the post-by-post emails properly read from
> >>> top to bottom.
> >>
> >> That's why other newsgroups allow top posting because the response in 
> >> each post is at the top, where the newsreader starts, so you don't have 
> >> to scroll over the text of the previous post to get to the important 
> >> stuff.
> >
> > This is not a newsgroup. It is an email list that archives emails
> > on the php.net web site, and has a newsgroup subscribed.
> 
> It *is* a newsgroup because I can access it through my newsreader. I can 
> recieve copies of posts in my email client, but I can only post using my 
> newsreader.
> 
> >> If a thread contained 30 posts would you really want the text of all 30 
> >> contained in the same message? How difficult would it be to separate one 
> >> message from another?
> >
> > What broken program (or script) puts the text of 30 posts into the
> > same post? You seem to be grasping at straws.
> 
> When you hit "reply" in your newsreader what happens? It creates a new post 
> with the original message quoted in its entirety. Some newsreadrs then 
> posiition the cursor at the  top ready for your reply, while others position 
> it at the bottom. If this happens 30 times then the last post contains 
> copies of the all the previous 29 messages.
> 
> >>> It's also about courtesy, not dropping dingleberries dozens or scores
> >>> of lines long (and some of you others could stand to snip the extraneous
> >>> even though you do properly bottom-post).
> >>
> >> So what are the rules about snipping then?
> >
> > You're the 30-year professional, figure them out. I'm Still Learnin'
> 
> Why should I have to figure it out? Surely some little Hitler has created a 
> rule so that the rest of us sheep don't have to think for ourselves?
> 
> -- 
> Tony Marston
> http://www.tonymarston.net
> http://www.radicore.org 
> 
> 

Someone has got to pay for this!!!
How dare you interrupt my 30years vampiric sleep over such trivial issue as top 
posting?. Now Tony you've been a good lad but this has got to end now! What's 
all the fuss about you not been able to abide by the rules here? If you can't 
abide, then simply leave (methinks the person that sent the mail in your name 
was actually trying to do you a favour). 
On the other hand, Daniel, what happened to that button with which you can ban 
any defauters on the list? is it broken?
Moreover, there seem to be one point that everybody's been missing all the 
while. since this argument started (or specifically somewhere along the line), 
Marston actually started following the rules. He has stopped top-posting 
without him even knowing it. Check his last few replies and you'll see.

The sun is up now so I got to return to my coven.

No more arguments guys.

Alugo Abdulazeez
http://www.frangeovic.com

_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx

--- End Message ---
--- Begin Message ---
I prefer to reduce SESSION usage as much as possible. but I dont hesitate to
use them if need arises.
Points to note

   - Execution time: Only session_id is stored on the client's computer, and
   the actual data is stored on the server. so it will take nearly same time to
   process 100 session vars and 1 session var.
   - Security: While passing data trough hidden form fields, it is easy for
   the user to be change it. but its impossible (the user can change the
   session_id though) for the user to change the data stored in a session.
   - register_globals: i always set this off. but my host turned this on.
   had to spend 2 full days to find out what the problem was.

coming back to you issue: IMHO storing stuff like" MaxDisplayRecords,
DefaultDisplayRecords, etc.," in a SESSION var is the best solution.
alternatives being

   - Hidden fields: this will add to unnecessary network traffic.
   - Use separate file: Why use a separate file if PHP does the job for you?
   - Use the database: If you have an existing connection this is OK. But
   this will become a bottle neck if u dont have an existing connection

--- End Message ---
--- Begin Message ---
At 11:31 PM -0400 7/9/09, D.M.Jackson wrote:
Hi,

    OK, I did a count on the session.inc file and there appears to be 37
variables accessed through the $_SESSION object.  By and large they all
appear to be scalar variables that contain a counter or a path or a boolean.
Nothing that looks like a big object.  Mostly stuff like" MaxDisplayRecords,
DefaultDisplayRecords, Theme, DefaultTheme, CustomerId, RealName,
CustomerBranch, Module, UserStockLocation, PageSize, AccessLevel,
AttemptsCounter, Language, PageSecurityToken, DatabaseName...etc.
    Initially, when you hit the index page the session.inc file is included.
From there, depending on what choices you make from the options displayed it
assembles a page by calling the a php file that calls the database if
needed, includes a header.inc file and a footer.inc file and builds the
appropriate html for the body and of course, includes the session.inc file.
        My question is, assuming 37 variables of this type in the
session.inc file, at what level of concurrent user access do you consider
changing the way you do business here.  Bare in mind that I don't comprehend
a whole lot about server and database clustering and big enterprise big iron
stuff like that.  I'm just a guy trying to learn how to write decent php
code that I don't have to be embarassed of when I shift gears in a new
direction to add a marketable skill in my career development path.


Mark:

Without seeing/understanding the code, I would consider dividing the "variables" into different groups -- those that are static (don't change during a user visit) and those that change depending upon *user* input.

For example, an admin might change a "static variable" OR a user might set a "static variable" in their preferences, but once set, then the variables really takes on the flavor of static rather than a real variable -- if that makes sense. That's my rational for the difference between a variable and a static variable, which is a contradiction in terms I know, but true none the less.

Those data that are static I would place in a require_once() include and load as needed.

Those data that change I would place in a table and use them as needed via calls to the database.

Variables with names like "CustomerId" and "RealName" appear to be values that change depending upon the customer. As such, then those items should (IMO) be placed in a relational database and only the "CustomerId" placed in a session and passed between pages. That way any page requiring the "RealName" of the customer can be obtained by a simple call to the database to pull the data associated with that "CustomerId". That type of data IMO should not be held in sessions -- but only the index to it.

For example, let's say your script is for an employee to process a customer's purchase. Once they have the customer ID, then all the data associated with that customer can be obtained from a single call to the database from a single session id instead of passing those data between pages via sessions. Do you see how that works?

In any event, that's the way I would do it.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
I faced the same problem many times. The reason turned out to be an
additional character outside </td> tags.
HTML formating software like Dreamweaver, HTML Tidy, Notepad++ will be
helpful in these cases. Above all use HTML Validatior extension for firefox.
Any ways this question has got nothing to do with PHP. Regarding firebug, it
shows the "generated" code, or the code seen by the browser, but not the
source code.

--- End Message ---
--- Begin Message ---
sorry, should have added that i'm not aware of any library to do this, but
you could certainly write one! :) and i forgot to use the list, sorry.

- isaac

On Fri, Jul 10, 2009 at 10:28 AM, Isaac Dover <isaacdo...@gmail.com> wrote:

> though this looks suspiciously like a homework assignment, i'll bite.
>
> those regex patterns wouldn't solve his problem. he wants to pull
> repetitions from the string _before_ knowing a pattern. those patterns will
> match the entire source string
>
> without trying, i would think that you may try using a technique that reads
> a character, then looks for the next occurrence of that character. if you're
> lucky, then that character will be the beginning of the sequence. you'll
> just look at the substring from that first occurrence until the next, then
> search the string for that substring.
>
> if unlucky, you'll move to the next string, _append it_ to the previous,
> repeat the process, and so on. at some point, you'll have the pattern built
> in memory and will be searching the source string using your built "pattern
> string". at some point, something will have to match.
>
> the trick is in recursion. also, i'm assuming your real examples are more
> complicated than what you have above. in the two listed, you already know
> that a zero indicates that the pattern is beginning, so you just look for,
> and note the index of, zeroes.
>
> i've thumbed through a free book online that deals with text parsing. it's
> very technical, but interesting at the same time. maybe you can find it.
>
> - isaac
>
>
> On Wed, Jul 8, 2009 at 11:32 PM, WenDong Zhang <zwd2...@gmail.com> wrote:
>
>> yes
>> (\d+?)\1+  works fine
>>
>> On Thu, Jul 9, 2009 at 6:00 AM, Per Jessen <p...@computer.org> wrote:
>>
>> > Rob Gould wrote:
>> >
>> > > Can anyone tell me if there's a PHP library out there that will help
>> > > me determine "pattern sequences" from a string?
>> > >
>> > >
>> > > Example input:
>> > >
>> > > 032258064516129032258064516129032258064516129032258064516129
>> > > Sequence = 032258064516129
>> > >
>> > >
>> > > 037037037037037037037037037037037037037037037037037037037037
>> > > Sequence = 037
>> > >
>> > >
>> > > I know regex can help you find a pattern when you know what the
>> > > pattern is already, but this is different.
>> >
>> > Nah, it's the same thing.
>> >
>> > A suitable regex might look something like this:
>> >
>> > /([0-9]+)\1+/
>> >
>> > Not tested, probably won't work on the first try.  You may need
>> > greediness adjustments.
>> >
>> >
>> > /Per
>> >
>> >
>> > --
>> > Per Jessen, Zürich (14.1°C)
>> >
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>> >
>>
>>
>> --
>> Best Regards!
>> Wen Dong
>>
>
>

--- End Message ---
--- Begin Message ---
On Fri, Jul 10, 2009 at 10:30 AM, Isaac Dover<isaacdo...@gmail.com> wrote:
>> On Wed, Jul 8, 2009 at 11:32 PM, WenDong Zhang <zwd2...@gmail.com> wrote:
>> On Thu, Jul 9, 2009 at 6:00 AM, Per Jessen <p...@computer.org> wrote:
>> > A suitable regex might look something like this:
>> >
>> > /([0-9]+)\1+/
>> >
>> > Not tested, probably won't work on the first try.  You may need
>> > greediness adjustments.
>> >
>> >
>> > /Per
>>
>> yes
>> (\d+?)\1+  works fine
>>
>>
>>
>> --
>> Best Regards!
>> Wen Dong
> those regex patterns wouldn't solve his problem. he wants to pull
> repetitions from the string _before_ knowing a pattern. those patterns will
> match the entire source string
>
> - isaac

Those patterns look like a pretty good starting point to me. True, the
first captured result of preg_match would be the entire string, but
the submatches array would contain the actual sequence that is
repeated:

<?php

$pattern = '/(\d+?)\1+/';

$subject = '032258064516129032258064516129032258064516129032258064516129';
if (preg_match($pattern, $subject, $matches)) {
    var_dump($matches);
}

/*
array(2) {
  [0]=>
  string(60) "032258064516129032258064516129032258064516129032258064516129"
  [1]=>
  string(15) "032258064516129"
}
*/

$subject = '037037037037037037037037037037037037037037037037037037037037';
if (preg_match($pattern, $subject, $matches)) {
    var_dump($matches);
}
/*
array(2) {
  [0]=>
  string(60) "037037037037037037037037037037037037037037037037037037037037"
  [1]=>
  string(3) "037"
}
*/

$subject = '333333333333333333333333333333333333333333333333333333333333';
if (preg_match($pattern, $subject, $matches)) {
    var_dump($matches);
}
/*
array(2) {
  [0]=>
  string(60) "333333333333333333333333333333333333333333333333333333333333"
  [1]=>
  string(1) "3"
}
*/

?>



Some slight adjustments to the pattern could also be useful.

// This would catch a pattern of any repeating characters, not just
numeric digits
$pattern = '/(.+?)\1+/';

// This would only match if the entire string was a repeated sequence
$pattern = '/^(\d+?)\1+$/';

// This would match the repeated sequence only if the string began
with a repeated sequence.
$pattern = '/^(\d+?)\1+/';

// This would match the repeated sequence only if the string ended
with a repeated sequence.
$pattern = '/(\d+?)\1+$/';

If a string had multiple sequences, you could also use preg_match_all
to find each sequence, but that looks a bit more involved than the OP.

None of these require knowing the sequence in advance. How do they not
satisfy the OP?

Andrew

--- End Message ---
--- Begin Message ---
i just got pwned!

thanks, andrew. i should've paid more attention to what i was reading.

- isaac

On Fri, Jul 10, 2009 at 11:19 AM, Andrew Ballard <aball...@gmail.com> wrote:

> On Fri, Jul 10, 2009 at 10:30 AM, Isaac Dover<isaacdo...@gmail.com> wrote:
> >> On Wed, Jul 8, 2009 at 11:32 PM, WenDong Zhang <zwd2...@gmail.com>
> wrote:
> >> On Thu, Jul 9, 2009 at 6:00 AM, Per Jessen <p...@computer.org> wrote:
> >> > A suitable regex might look something like this:
> >> >
> >> > /([0-9]+)\1+/
> >> >
> >> > Not tested, probably won't work on the first try.  You may need
> >> > greediness adjustments.
> >> >
> >> >
> >> > /Per
> >>
> >> yes
> >> (\d+?)\1+  works fine
> >>
> >>
> >>
> >> --
> >> Best Regards!
> >> Wen Dong
> > those regex patterns wouldn't solve his problem. he wants to pull
> > repetitions from the string _before_ knowing a pattern. those patterns
> will
> > match the entire source string
> >
> > - isaac
>
> Those patterns look like a pretty good starting point to me. True, the
> first captured result of preg_match would be the entire string, but
> the submatches array would contain the actual sequence that is
> repeated:
>
> <?php
>
> $pattern = '/(\d+?)\1+/';
>
> $subject = '032258064516129032258064516129032258064516129032258064516129';
> if (preg_match($pattern, $subject, $matches)) {
>    var_dump($matches);
> }
>
> /*
> array(2) {
>  [0]=>
>  string(60) "032258064516129032258064516129032258064516129032258064516129"
>  [1]=>
>  string(15) "032258064516129"
> }
> */
>
> $subject = '037037037037037037037037037037037037037037037037037037037037';
> if (preg_match($pattern, $subject, $matches)) {
>    var_dump($matches);
> }
> /*
> array(2) {
>  [0]=>
>  string(60) "037037037037037037037037037037037037037037037037037037037037"
>  [1]=>
>  string(3) "037"
> }
> */
>
> $subject = '333333333333333333333333333333333333333333333333333333333333';
> if (preg_match($pattern, $subject, $matches)) {
>    var_dump($matches);
> }
> /*
> array(2) {
>  [0]=>
>  string(60) "333333333333333333333333333333333333333333333333333333333333"
>  [1]=>
>  string(1) "3"
> }
> */
>
> ?>
>
>
>
> Some slight adjustments to the pattern could also be useful.
>
> // This would catch a pattern of any repeating characters, not just
> numeric digits
> $pattern = '/(.+?)\1+/';
>
> // This would only match if the entire string was a repeated sequence
> $pattern = '/^(\d+?)\1+$/';
>
> // This would match the repeated sequence only if the string began
> with a repeated sequence.
> $pattern = '/^(\d+?)\1+/';
>
> // This would match the repeated sequence only if the string ended
> with a repeated sequence.
> $pattern = '/(\d+?)\1+$/';
>
> If a string had multiple sequences, you could also use preg_match_all
> to find each sequence, but that looks a bit more involved than the OP.
>
> None of these require knowing the sequence in advance. How do they not
> satisfy the OP?
>
> Andrew
>

--- End Message ---
--- Begin Message --- I'm having a hard time getting my head around this problem. I have to connect to a FoxPro database using an ODBC driver. Sometimes when I connect I get an error. The error doesn't occur all the time and usually another connect attempt works. I can trap the error through an error handler. However, I use a class to connect to the database. What I want to do is to check for that error and, if it occurs, try to connect again. Since the error handler is outside the class, how can I create the object again and make sure it gets passed back to my script that called it? I hope that made sense!

Thanks!
Floyd

--- End Message ---
--- Begin Message ---
On Fri, Jul 10, 2009 at 10:56 AM, Floyd Resler<fres...@adex-intl.com> wrote:
> I'm having a hard time getting my head around this problem.  I have to
> connect to a FoxPro database using an ODBC driver.  Sometimes when I connect
> I get an error.  The error doesn't occur all the time and usually another
> connect attempt works.  I can trap the error through an error handler.
>  However, I use a class to connect to the database.  What I want to do is to
> check for that error and, if it occurs, try to connect again.  Since the
> error handler is outside the class, how can I create the object again and
> make sure it gets passed back to my script that called it?  I hope that made
> sense!
>
> Thanks!
> Floyd

Why is the error outside the class? If you connect with a class, something like:

public function __construct() {
  $this->handle = false;
  while($this->handle === false) {
    $this->handle == odbc_connect();
  }
}

ought to work fine.  Alternatively, you could check out PDO, which is
supposed to be the next generation of database connections in PHP, and
won't create an object without a connection.

--- End Message ---
--- Begin Message ---
Eddie,
Thanks for the tip. It suddenly occurred to me what I was doing wrong. I do use an error trap but I was telling my script to stop running after the error. So, now I ignore it and continue through the loop you suggested. I guess it was working exactly the way I had written it!

Thanks!
Floyd

On Jul 10, 2009, at 11:23 AM, Eddie Drapkin wrote:

On Fri, Jul 10, 2009 at 10:56 AM, Floyd Resler<fres...@adex- intl.com> wrote:
I'm having a hard time getting my head around this problem. I have to connect to a FoxPro database using an ODBC driver. Sometimes when I connect I get an error. The error doesn't occur all the time and usually another connect attempt works. I can trap the error through an error handler. However, I use a class to connect to the database. What I want to do is to check for that error and, if it occurs, try to connect again. Since the error handler is outside the class, how can I create the object again and make sure it gets passed back to my script that called it? I hope that made
sense!

Thanks!
Floyd

Why is the error outside the class? If you connect with a class, something like:

public function __construct() {
 $this->handle = false;
 while($this->handle === false) {
   $this->handle == odbc_connect();
 }
}

ought to work fine.  Alternatively, you could check out PDO, which is
supposed to be the next generation of database connections in PHP, and
won't create an object without a connection.



--- End Message ---

Reply via email to