[PHP] IMAP and NNTP
The manual says that the majority of IMAP commands can be used for NNTP access. This code works fine. $status = imap_status($nntp,{news.gradwell.net:119/nntp}#news.gradwell. lists.test,SA_ALL); if($status) { print(Messages: . $status-messages ).br\n; print(Recent: . $status-recent ).br\n; print(Unseen: . $status-unseen ).br\n; print(UIDnext:. $status-uidnext).br\n; print(UIDvalidity:. $status-uidvalidity).br\n; This produces the following output. Messages: 7 Recent: 7 Unseen: 7 UIDnext: 111 UIDvalidity:-1091568946 The 111 is reasonable as there are 6 messages on the server, numbered 104-109 on the server. The code $msgno = imap_msgno($nntp, '106'); echo msgno is: $msgno br\n; outputs msgno is: 2 the inverse $uidno = imap_uid($nntp, $msgno); echo uidno is: $uidno br\n; outputs Warning: Bad message number in /nfs1/corixa/webs/cgi-user/news/news.php on line 60 uidno is: So it appears that 106 looks up as 2, but 2 doesn't produce 106, but an error instead. Has anybody honestly used the IMAP functions to drive and NNTP server or am I wasting my time. {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] MySQL and PHP arrays
Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL and PHP arrays
On Mon, 10 Mar 2003 22:34:44 +0800, Jason Wong wrote: On Monday 10 March 2003 22:30, {R}ichard Ashton wrote: Is there a generally recommended way of storing an array created by PHP in a MySQL database field ? serialize() and unserialize(). What type of field should it be, and how do you get the whole array back in one go without reconstructing it row by row, if that is possible? Any text field will do, just make sure it's large enough for your data. Thanks that now makes much more sense. So when I look at the data in the database I see a:142:{i:1;s:52:[52characters];i:2;s:37:[37characters] and so on for the 142 elements of the array. But getting it out is not so easy. $result = mysql_query( select post from posts where id = '$id' ) Gives $result as a Resource id #6 which is OK but I cant find the PHP MySQL command to get the whole field back to unserialize it :( {R} -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* QOTD: I'm not bald -- I'm hair challenged. [I thought that was differently haired. Ed.] */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match fails to fill $matches
I have At the top of a loop $ts = '/(' . $trigger_string .')/is'; echo trigger_string is $ts br; $matches = array(); $hit = array(); In the loop $hit[] = preg_match ($ts, $line_in,$matches); Now the $hit array fills up correctly, if the trigger string is on the line just read in, putting 1 or 0 in $hits. But the string that triggered the match is not put in $matches. The manual says it should be. Anyone any idea what I am doing wrong ? {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match fails to fill $matches
On Wed, 5 Mar 2003 10:21:30 -0500, 1LT John W. Holmes wrote: $ts = '/(' . $trigger_string .')/is'; echo trigger_string is $ts br; $matches = array(); $hit = array(); In the loop $hit[] = preg_match ($ts, $line_in,$matches); Now the $hit array fills up correctly, if the trigger string is on the line just read in, putting 1 or 0 in $hits. But the string that triggered the match is not put in $matches. The manual says it should be. What's your actual code? How are you looking for the match in $matches? If something was matched, then it'll be there. The full cod in the loop is. $cnt = 0; while(!feof($fp)) { // Get body $line_in = fgets($fp,4096); $cnt++; // looking for the other end of the marker found above if (substr($line_in,2,strlen($line_in)-5) != $marker ) { $body= $body . $line_in; $hit[] = preg_match ($ts, $line_in,$matches); $line[] = $line_in; $char= substr($line_in,0,1); $quote[] = preg_match ($qs, $char); } if (strpos($line_in, $marker) 0 ) { break; } } Later on in the code after the loop I do echo printing array matches br; print_r ($matches);echo br; echo printing array hit br; print_r ($hit); echo printing array quote br; print_r ($quote); echo printing array lins br; print_r ($line); $lcnt = count($line); echo cnt of line array is $lcnt br; $hcnt = count($hit); echo cnt of hit array is $hcnt br; $qcnt = count($quote); echo cnt of quote array is $qcnt br; $mcnt = count($matches); echo cnt of matches array is $mcnt br; the arrays $hit and $line and $quote all print data, and all the count($array) print a value except the $matches array and count are empty. {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match fails to fill $matches
On Wed, 5 Mar 2003 12:06:41 -0500, 1LT John W. Holmes wrote: The full code in the loop is. Later on in the code after the loop I do echo printing array matches br; print_r ($matches);echo br; $matches is going to be over-written after every time through the loop! It doesn't add it all up. Add in a $var[] = $matches; or something inside of your loop to keep track of them all, then print_r($var) to see what it contains. Thanks that fixed it I ended up with. with the $ts string | and | the | $hit[] = preg_match ($ts, $line_in,$var); $matches[] = $var; but it still it needed $var = array(); before it would work. The results are interesting and shows I don't understand arrays :( print_r ($matches); printing array matches (reformatted) Array ( [0] = Array ( ) [1] = Array ( ) [2] = Array ( ) [3] = Array ( ) [4] = Array ( ) [5] = Array ( ) [6] = Array ( [0] = and [1] = and ) [7] = Array ( [0] = the [1] = the ) [8] = Array ( [0] = and [1] = and ) [9] = Array ( ) [10] = Array ( ) [11] = Array ( ) [12] = Array ( [0] = and [1] = and ) [13] = Array ( ) [14] = Array ( ) [15] = Array ( ) [16] = Array ( [0] = the [1] = the ) [17] = Array ( ) [18] = Array ( [0] = and [1] = and ) [19] = Array ( ) [20] = Array ( ) So how do you interpret that a sort of instant 2D array. {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String searching peformance
On Mon, 24 Feb 2003 22:35:35 +0100, Ernest E Vogelsinger wrote: At 21:22 24.02.2003, {R}ichard Ashton spoke out and said: [snip] while ( $flag == true ) if (strpos($body, $word[]) 0) {$flag=false} What I really need to know is which is the fastest loop? Which is the fastest match, strpos? Which is the fastest comparison? What other optimisations are possible to maximise search speed? I would expect to keep a frequency hit count and sort the $words[] so that the most frequent hits are found first, remembering that only $body with NO $words in then are automatically posted, so every word must be tested. I don't know sufficient internals to pick the fastest method. I will be running with 4.3.1 on FreeBSD 4.6 [snip] I'd suggest something like this: $buzzwords = array('idiot', 'fool', 'shit', 'FOAD'); $re = '/(' . implode('|',$buzzwords).')/is'; if (preg_match($re, $posting)) // bad word found else // cleared Thank you very much that is brilliant, I would never have thought of that. Do you think that: if (preg_match($re, $posting, $hits)) would slow it down at all. The $buzzwords will be kept in a file to be loaded before each run, every 5 minutes. I could therefore keep a count of which words hit most frequently and move them to the top of the list. {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Splitting up big strings
I have the body ov a Usnet article, all of it, in $body. I want to split it into lines. I have tried $lines = explode( X, $body); where I have used X = 0x0A X = '0x0A' X = 0x0D X = '0x0A' X = \r -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Splitting up big strings
On Thu, 27 Feb 2003 01:02:54 +0800, Jason Wong wrote: On Thursday 27 February 2003 00:54, {R}ichard Ashton wrote: I have the body ov a Usnet article, all of it, in $body. I want to split it into lines. I have tried $lines = explode( X, $body); where I have used X = 0x0A X = '0x0A' X = 0x0D X = '0x0A' X = \r Try \n. If I hadn't pushed send by mistake I would have added X = \r X = '\r' X = \n X = '\n' I then have echo pieces $pieces[0] br; echo pieces $pieces[1] br; echo pieces $pieces[2] br; echo pieces $pieces[3] br; echo pieces $pieces[4] br; echo pieces $pieces[5] br; If I look at $body with Hex editor there are lots of 0D 0A pairs and further if I look at the source of the page generated by echo $body; I can see the CRLF's This is giving me pains in the neck :( {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String searching peformance
On Wed, 26 Feb 2003 17:47:41 +0800, Jason Wong wrote: On Wednesday 26 February 2003 16:49, {R}ichard Ashton wrote: Do you think that: if (preg_match($re, $posting, $hits)) would slow it down at all. The $buzzwords will be kept in a file to be loaded before each run, every 5 minutes. I could therefore keep a count of which words hit most frequently and move them to the top of the list. No idea whether this would be faster (it's certainly easier to code): explode() text into an array place your banned words into an array array_intersect() to find words common in both Thanks for another method, Do your own benchmarking! That is the easy bit. {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] String searching peformance
I am looking for the most efficient way to search for Trigger words in a big string. I have a string, $body which is all of the body of any particular Usenet Post, so it can be as short as Me too and up to some, as yet undecided, limit say around 10Kbytes. I have a list of words in an array, maybe 50 words of up to 8 characters. I need to search the $body for the presence of $word and if any $word in the array is found in $body Trigger an action. This is a moderation bot for a beginners group, NO Flaming No swearing No Abuse, you can imagine a list of words, idiot, fool, shit, FOAD, and so on. When *any* one is found the post is diverted for manual intervention, and searching stops. Just guessing I would imagine while ( $flag == true ) if (strpos($body, $word[]) 0) {$flag=false} What I really need to know is which is the fastest loop? Which is the fastest match, strpos? Which is the fastest comparison? What other optimisations are possible to maximise search speed? I would expect to keep a frequency hit count and sort the $words[] so that the most frequent hits are found first, remembering that only $body with NO $words in then are automatically posted, so every word must be tested. I don't know sufficient internals to pick the fastest method. I will be running with 4.3.1 on FreeBSD 4.6 {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PGP signing text from called from PHP
Using PHP 4.1.2 I need to PGP sign a piece of text and detached the signature. I have read a lot in the archives and and about the better exec() calls in 4.3. However I cannot find a reference that indicates the best way to pass a set of arguments out of a PHP script to PGP. I need to use pgp2.6.3i the pgp command line looks like a bit this pgp -sabf -u pgpuser pgppassphrase text pgpsignature This has to be given to the Bash Shell with whatever works exec() system() or passthrough(), any output can be retrieved later . It is possible, if anyone knows how, to set ENV variable in the shell to preload the passphrase and the pgpuser into ENV variables. Has anyone cracked this? Any pointers to archived messages I have missed. Any suggestions at all would be most welcome. {R} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php