Click here to Skip to main content
15,892,059 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
QuestionIntitialize a session variable after onclick event is fired Pin
pandu web dev11-Aug-13 23:16
pandu web dev11-Aug-13 23:16 
AnswerRe: Intitialize a session variable after onclick event is fired Pin
Kaivan Alimohammadi23-Aug-13 10:25
Kaivan Alimohammadi23-Aug-13 10:25 
GeneralRe: Intitialize a session variable after onclick event is fired Pin
pandu web dev26-Aug-13 3:28
pandu web dev26-Aug-13 3:28 
QuestionContact form - Bootstrap Error Validation Pin
bigcdh4-Aug-13 8:13
bigcdh4-Aug-13 8:13 
AnswerRe: Contact form - Bootstrap Error Validation Pin
Peter_in_27808-Aug-13 15:42
professionalPeter_in_27808-Aug-13 15:42 
AnswerRe: Contact form - Bootstrap Error Validation Pin
vbmike23-Aug-13 9:12
vbmike23-Aug-13 9:12 
GeneralRe: Contact form - Bootstrap Error Validation Pin
bigcdh23-Aug-13 9:22
bigcdh23-Aug-13 9:22 
QuestionPHP find all occurrences of string in file Pin
MicahC5-Jul-13 6:44
MicahC5-Jul-13 6:44 
Greetings

I am using PHP to read the contents of a log file. I am trying to find all occurrences of a string (with spaces) in this file. I understand reading the entire file is inefficient, but its the only to grab the log data.

Log output (/sda1/user/dns/log/dnsmasq.log):
Jul 5 11:28:25 dnsmasq[22873]: reply 1.courier-push-apple.com.akadns.net is xx.xxx.xx.xxx

Using PHP I am trying to count the number of occurrences the string 'Jul 5' appears in the file.

Depending on how I open the file (to a string) I can use
$instances = substr_count($string, 'Jul 5 ');

However, the space between Jul and 5 seems to be causing some problems. If I just search for 'Jul' it works, but returns 0 on 'Jul 5'.

I have also tried:
$today = date("M j");  //Jul 5
$file = file('/sda1/user/dns/log/dnsmasq.log');
$occurrences = preg_match_all('/'.$today.'/', $file);


This works, but reading from a file does not.
PHP
$getText = 'Jul 5 is todays dataJul 5 is today today is Jul 5';
$occurrences =  substr_count($getText, $today); 
echo $occurrences; //3 occurrences


Any help getting PHP to find all occurrences of a string with spaces from a file would be greatly appreciated.
AnswerRe: PHP find all occurrences of string in file Pin
Graham Breach5-Jul-13 21:20
Graham Breach5-Jul-13 21:20 
GeneralRe: PHP find all occurrences of string in file Pin
MicahC7-Jul-13 19:52
MicahC7-Jul-13 19:52 
GeneralRe: PHP find all occurrences of string in file Pin
MicahC10-Jul-13 5:56
MicahC10-Jul-13 5:56 
QuestionNot much traffic here is there..... Pin
Erudite_Eric16-Jun-13 23:40
Erudite_Eric16-Jun-13 23:40 
AnswerRe: Not much traffic here is there..... Pin
Ali Al Omairi(Abu AlHassan)7-Jul-13 22:18
professionalAli Al Omairi(Abu AlHassan)7-Jul-13 22:18 
QuestionCounting Menu Items & Determining If First/Last Pin
NickBogi7-Jun-13 13:20
NickBogi7-Jun-13 13:20 
AnswerGot It Working Pin
NickBogi10-Jun-13 8:29
NickBogi10-Jun-13 8:29 
QuestionUrgent !!! Looking for the best solution Pin
MacAriel15-May-13 8:43
MacAriel15-May-13 8:43 
AnswerRe: Urgent !!! Looking for the best solution Pin
herlon21423-Jul-13 9:59
herlon21423-Jul-13 9:59 
QuestionVideo Gallery for wordpress site. Pin
Neha Pandal12-May-13 10:03
professionalNeha Pandal12-May-13 10:03 
AnswerRe: Video Gallery for wordpress site. Pin
Archie22is30-Jun-13 21:07
Archie22is30-Jun-13 21:07 
Questionhow to store QR Code image in mysql with php Pin
blertaaa2-May-13 22:43
blertaaa2-May-13 22:43 
AnswerRe: how to store QR Code image in mysql with php Pin
Prasad Khandekar21-May-13 4:56
professionalPrasad Khandekar21-May-13 4:56 
AnswerRe: how to store QR Code image in mysql with php Pin
Resalat Haque Prodhan27-Jun-13 2:02
Resalat Haque Prodhan27-Jun-13 2:02 
AnswerRe: how to store QR Code image in mysql with php Pin
Rony Sur2-Jul-13 0:04
professionalRony Sur2-Jul-13 0:04 
QuestionHow to install xampp or Lamp in Ubuntu 8 Pin
Member 992947820-Mar-13 20:55
Member 992947820-Mar-13 20:55 
AnswerRe: How to install xampp or Lamp in Ubuntu 8 Pin
Richard MacCutchan20-Mar-13 22:54
mveRichard MacCutchan20-Mar-13 22:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.