Re: [PHP] PHP script for detecting pattern sequences?

2009-07-08 Thread WenDong Zhang
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


Re: [PHP] Cleaning up automatically when leaving a page

2009-06-30 Thread WenDong Zhang
yes, the browser evoke unload event when leave the page (back, forward, or
close). you can send a message via ajax, but it may not been received by the
server successful, (when close the browser)

I think the best way is maintaining a timestamp as michael  paul say, and
clear the 'junk' timely.

there is another way if you need to get some INFO when user leaves this page
(such as leave time...):
 save the INFO into cache
 set time interval do the follow:
  1. load INFO from cache
  2. send the INFO via ajax and wait the server confirm it has received the
INFO
  3. if the server response is ture, delete the INFO or send the INFO again
a while later
by this way, even users closed their browser, but the next time they open
your web page, they will send the cached INFO too.

On Wed, Jul 1, 2009 at 10:59 AM, Paul M Foster pa...@quillandmouse.comwrote:

 On Tue, Jun 30, 2009 at 06:38:19PM -0700, Mary Anderson wrote:

  Hi all,
 
I have a php application for which I have a page which creates
  temporary junk and puts it into a persistent store  (in this case a
  postgres database, but that is beside the point.)
 
I have a Save button which puts the stuff I really want into the
  persistent store and cleans up the temporary junk.  I have a Cancel
  button which only cleans up the temporary junk.
 
 I would really like to have the cleanup code run anytime a user
  leaves the page without hitting the Save button.  Is there anyway to do
  this?  I.e. have php code called conditionally on exiting the page?

 If the user hits the Back button or exits via clicking on some link on
 the page, there's no reasonable way to do this (Michael's cron versions
 excepted). Because the HTTP protocol has no effective memory, there's no
 way for it to know that the user exited without saving. You can do
 various tricky things like set a $_SESSION variable, and then have it
 checked at the top of each page where the user could go, and check and
 clean up if the variable has a certain value. But that's pretty tedious.
 You could execute the whole thing as part of a class, and put a check in
 the constructor of the class (where it will be called on every page)
 which cleans up if necessary.

 In other words, there are ways to do this, but they are tedious. The
 PHP/HTTP execution engines have no way of doing it on their own.

 (Oh, there may be a way to do this with Javascript. I'm not good with
 Javascript, but maybe there's some OnExit event which you could use to
 cause a Javascript function to do an AJAX call to a PHP script which
 cleans up. I dunno.)

 Paul

 --
 Paul M. Foster

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




-- 
Best Regards!
Wen Dong


Re: [PHP] fixing new lines from textarea in an email?

2009-06-27 Thread WenDong Zhang
how about preg_replace('/(\\n}\\r\\n)/', 'br /', $_POST[problem]);

On Sat, Jun 27, 2009 at 12:50 AM, Adam Williams
awill...@mdah.state.ms.uswrote:



 Daniel Brown wrote:

In a cursory glance, I've noticed the following code:

 htmlspecialchars(nl2br(str_replace('\r','',$_POST[problem])))

You are using a literal '\r' in your str_replace() function.  This
 should instead be replaced with double quotes to translate the \r to
 its appropriate EOL character:

 htmlspecialchars(nl2br(str_replace(\r,'',$_POST[problem])))




 Thanks, I didn't know that single vs double quotes in that instance made a
 difference.  I've made the change to my code.



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




-- 
Best Regards!
Wen Dong


[PHP] Does php have multithread, shared object(like jsp application)

2009-06-25 Thread WenDong Zhang
Hi guys:

Now days I want to develop a web application like a chat room. the requests
per seconds maybe very large, so I want to save some common info into to
memory (quick access).

So, I want to know does php have the follow features or implement them in
other ways.
1. server scope objects, mostly like application in jsp.  // the most
important~
2. multithread synchronize.
3. I want to start a thread timed execute, like Timer in java

thanks
-- 
Best Regards!
Wen Dong