extracting characters between \# symbols

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

extracting characters between \# symbols

Post by raghavan20 »

Extract characters between '#'

Code: Select all

$str10 = "#this is me#";
echo preg_match("/\#[^\n]+\#/", $matches, $str10);
this does not seem to match any substring in the $str10. why???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

preg_match_all('@#(.*?)#@m',$str10,$matches);
print_r($matches);
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Array ( [0] => Array ( [0] => #this is me# ) [1] => Array ( [0] => this is me ) )
the first one returned with quotes and the next one without the quotes. wots the meaning of that??
does this 'm' denote "PCRE_MULTILINE"?
If you dont mind, can you say wots this (.*?)
thanks for your help again
Last edited by raghavan20 on Thu Aug 25, 2005 8:48 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

raghavan20 wrote:
Array ( [0] => Array ( [0] => #this is me# ) [1] => Array ( [0] => this is me ) )
the first one returned with quotes and the next one without the quotes. wots the meaning of that??
$matches[0] is an array of full full pattern matches found by the regex engine.
$matches[1] is an array of the first captured object (the data that matches .*? in this instance)
raghavan20 wrote:does this 'm' denote "PCRE_MULTILINE"?
m is multi-line mode, yes.
raghavan20 wrote:If you dont mind, can you say wots this (.*?)
.*? is called an ungreedy matching. It will find the shortest text that fulfills the entire pattern. To illustrate:

Code: Select all

$text = 'this #is a string# with #two sets of hash markers#
here on the #second line# we have another hash marker';

// without the ?
preg_match_all('@#(.*)#@m',$text,$matches);
print_r($matches);

// with the ?
preg_match_all('@#(.*?)#@m',$text,$matches);
print_r($matches);
outputs

Code: Select all

Array
(
    [0] => Array
        (
            [0] => #is a string# with #two sets of hash markers#
            [1] => #second line#
        )

    [1] => Array
        (
            [0] => is a string# with #two sets of hash markers
            [1] => second line
        )

)
Array
(
    [0] => Array
        (
            [0] => #is a string#
            [1] => #two sets of hash markers#
            [2] => #second line#
        )

    [1] => Array
        (
            [0] => is a string
            [1] => two sets of hash markers
            [2] => second line
        )

)
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

When I was reading regex tutorials, they said that it is preferrable to use [^#] instead of .*? I dont really understand why???

so I thought of this

Code: Select all

preg_match_all('/^#[^#]+#$/',$str10,$matches); 
print_r($matches); 

but it returns
//Array ( [0] => Array ( [0] => #this is me# ) )
I dont understand a few things from the result
1. why is the first array element empty?
2. how do I get the matched string excluded braces as you did with your regex expression .*?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

raghavan20 wrote:When I was reading regex tutorials, they said that it is preferrable to use [^#] instead of .*? I dont really understand why???
it can be potentially faster, but it's likely more to make it easier for nonregex people to understand :) But those are a guess, I've never benchmarked the two variants.
raghavan20 wrote:I dont understand a few things from the result
1. why is the first array element empty?
it's not empty. preg_match_all() returns two dimensional arrays. You're looking at the zeroth element's array of data.
raghavan20 wrote:2. how do I get the matched string excluded braces as you did with your regex expression .*?

Code: Select all

preg_match_all('/^#([^#]+)#$/',$str10,$matches);
print_r($matches);
notice this modification of my previous example:

Code: Select all

<?php

$text = 'this #is a string# with #two sets of hash markers#
here on the #second line# we have another hash marker';

// without the ?
preg_match_all('@#([^#]+)#@m',$text,$matches);
print_r($matches);

// with the ?
preg_match_all('@#([^#]+?)#@m',$text,$matches);
print_r($matches);

?>
outputs

Code: Select all

Array
(
    [0] => Array
        (
            [0] => #is a string#
            [1] => #two sets of hash markers#
            [2] => #second line#
        )

    [1] => Array
        (
            [0] => is a string
            [1] => two sets of hash markers
            [2] => second line
        )

)
Array
(
    [0] => Array
        (
            [0] => #is a string#
            [1] => #two sets of hash markers#
            [2] => #second line#
        )

    [1] => Array
        (
            [0] => is a string
            [1] => two sets of hash markers
            [2] => second line
        )

)
(these have been run through php 5.0.4)
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Thanks for your help

raghavan20 wrote:
I dont understand a few things from the result
1. why is the first array element empty?
it's not empty. preg_match_all() returns two dimensional arrays. You're looking at the zeroth element's array of data.
I was asking why the first element was empty??? while yours returned something.

I see you avatar changed. I really wanted to know why most of the IT guys are more inclined towards using 'monkey' in their names like you :wink:
Last edited by raghavan20 on Fri Aug 26, 2005 7:08 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

monkey often comes from being called a "Code Monkey," although I'm not entirely sure why other than I can write code very quickly.

As for a continued explanation of why mine has something in the zeroth element: Yours only had the zeroth element, actually. The parentheses I use tells the regex engine to remember and return the text within that context of the matching pattern. You didn't have any parentheses to tell it that. If you look at your output in the command line, you may understand more. (i.e. you're not seeing the carriage returns and tabs print_r() is placing)
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

raghavan20 wrote:I really wanted to know why most of the IT are more inclined towards using 'monkey' in their names like you :wink:
...because he's L337 :lol:
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

I am trying to read commands from a backup file which has database, table structures statements and insert statements.
Here is the sample of how the file is structured

Code: Select all

#
#http://www.yourresourcecenter.com Backup software
#DATE: 27-08-2005 12:43:42
#
#Database :raghavan_Cms
#
CREATE DATABASE `raghavan_Cms`;
USE `raghavan_Cms`;


#Blogs_tbl
CREATE TABLE `Blogs_tbl` (
  `BlogId` int(5) unsigned NOT NULL auto_increment,
  `MemberId` varchar(5) NOT NULL default '',
  `Title` varchar(50) NOT NULL default '',
  `Description` text,
  `Date` date NOT NULL default '0000-00-00',
  PRIMARY KEY  (`BlogId`)
) TYPE=MyISAM;

#
#raghavan_Cms.Blogs_tbl: Table data
#

INSERT INTO raghavan_Cms.Blogs_tbl VALUES(1,'M1003','Beautiful','blog on all the beautiful  places across the world!!!','2005-05-25');


#ChatMessages_tbl
CREATE TABLE `ChatMessages_tbl` (
  `Id` int(10) unsigned NOT NULL auto_increment,
  `ChatRoomId` int(11) unsigned NOT NULL default '0',
  `FromId` int(10) unsigned NOT NULL default '0',
  `RecipientId` int(11) unsigned default '0',
  `Time` timestamp(14) NOT NULL,
  `Message` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`Id`),
  KEY `ChatRoomId` (`ChatRoomId`)
) TYPE=MyISAM;

#
#raghavan_Cms.ChatMessages_tbl: Table data
#



#ChatRooms_tbl
CREATE TABLE `ChatRooms_tbl` (
  `Id` int(11) NOT NULL auto_increment,
  `Name` varchar(25) NOT NULL default '',
  `Description` varchar(100) default NULL,
  `MaxUsersAllowed` int(11) NOT NULL default '200',
  KEY `Id` (`Id`,`Name`,`MaxUsersAllowed`)
) TYPE=MyISAM;

#
#raghavan_Cms.ChatRooms_tbl: Table data
#

INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(1,'General Discussion','can talk about anything here',100);
INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(2,'Technology - Hardware','Can talk about hardware and networking',100);
INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(3,'Techonology - Software','Talk about any language, software or anything relevant to it',5);


#ChatUsers_tbl
CREATE TABLE `ChatUsers_tbl` (
  `Id` int(10) unsigned NOT NULL auto_increment,
  `ChatRoomId` int(10) unsigned NOT NULL default '0',
  `UserName` varchar(20) NOT NULL default '',
  `LastUpdate` timestamp(14) NOT NULL,
  `SessionId` varchar(32) default NULL,
  PRIMARY KEY  (`Id`),
  UNIQUE KEY `UserName` (`UserName`),
  KEY `ChatRoomId` (`ChatRoomId`)
) TYPE=MyISAM;

#
#raghavan_Cms.ChatUsers_tbl: Table data
#

INSERT INTO raghavan_Cms.ChatUsers_tbl VALUES(3,1,'Mini','20050826073821','df0aec64d22aa8808a449aac87af8483');


#Images_tbl
CREATE TABLE `Images_tbl` (
  `ImageId` varchar(5) NOT NULL default '',
  `Location` text NOT NULL,
  PRIMARY KEY  (`ImageId`)
) TYPE=MyISAM;

#
#raghavan_Cms.Images_tbl: Table data
#

INSERT INTO raghavan_Cms.Images_tbl VALUES('I1001','/images/avatars/000.gif');
INSERT INTO raghavan_Cms.Images_tbl VALUES('I1002','/images/avatars/001.gif');
INSERT INTO raghavan_Cms.Images_tbl VALUES('I1003','/images/avatars/002.gif');
INSERT INTO raghavan_Cms.Images_tbl VALUES('I1004','/images/avatars/003.gif');
INSERT INTO raghavan_Cms.Images_tbl VALUES('I1005','/images/avatars/004.gif');
I use the following regex and I could read:

Code: Select all

preg_match_all("/[\n\r][^#](.+);\n/m", $this->commands, $matches);
		print_r($matches);
it prints:

Code: Select all

Array ( [0] => Array ( [0] => CREATE DATABASE `raghavan_Cms`; [1] => ) TYPE=MyISAM; [2] => INSERT INTO raghavan_Cms.Blogs_tbl VALUES(1,'M1003','Beautiful','blog on all the beautiful places across the world!!!','2005-05-25'); [3] => ) TYPE=MyISAM; [4] => ) TYPE=MyISAM; [5] => INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(1,'General Discussion','can talk about anything here',100); [6] => INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(3,'Techonology - Software','Talk about any language, software or anything relevant to it',5); [7] => ) TYPE=MyISAM; [8] => INSERT INTO raghavan_Cms.ChatUsers_tbl VALUES(3,1,'Mini','20050826073821','df0aec64d22aa8808a449aac87af8483'); [9] => ) TYPE=MyISAM; [10] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1001','/images/avatars/000.gif'); [11] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1003','/images/avatars/002.gif'); [12] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1005','/images/avatars/004.gif'); [13] => ) TYPE=MyISAM; [14] => ) TYPE=MyISAM; [15] => ) TYPE=MyISAM; [16] => INSERT INTO raghavan_Cms.MemberBlogMap_tbl VALUES('1','M1003'); [17] => INSERT INTO raghavan_Cms.MemberBlogMap_tbl VALUES('3','M1003'); [18] => INSERT INTO raghavan_Cms.MemberBlogMap_tbl VALUES('5','M1003'); [19] => ) TYPE=MyISAM; [20] => INSERT INTO raghavan_Cms.Members_tbl VALUES('M1001','raghavan','chock','raghavan20@rediffmail.com','0790790709','14, boughey rd','stoke','staffordshire','united kingdom','st15 9rd','I am a brave man and also enterprising.','2005-06-10','I1004'); [21] => INSERT INTO raghavan_Cms.Members_tbl VALUES('M1009','logesh','chitibabu','vaazstorm@yahoo.co.in','7944067945','117, college road','stoke on trent','Staffs','UK','st42ee','','2005-07-01','I1001'); [22] => INSERT INTO raghavan_Cms.Members_tbl VALUES('M1006','srinivaasan','sekhar','vaazstorm@yahoo.co.in','0790790790','117, college road','stoke - on - trent','staffordshire','united kingdom','st15 9rd','','2005-06-26','I1003'); [23] => INSERT INTO raghavan_Cms.Members_tbl VALUES('M1004','Diviya','Ganapathy','diviya@hotmail.com','0783007450','117, college road','stoke','staffordshire','united kingdom','st42ee','','2005-06-20','I1001'); [24] => INSERT INTO raghavan_Cms.Members_tbl VALUES('M1005','Murali','venugopal','murali@yahoo.com','0790790790','117, college road','stafford','staffordshire','united kingdom','st98 9df','','2005-06-24','I1001'); [25] => ) TYPE=MyISAM; [26] => INSERT INTO raghavan_Cms.Messages_tbl VALUES(1,'raghavan20','kannan','trial','hi, how are u?','Yes','2005-06-15'); [27] => INSERT INTO raghavan_Cms.Messages_tbl VALUES(3,'raghavan20','srinivasan','hi how do u do?','mate, its been a long time i mailed called in to see wot r u doing','No','2005-06-16'); [28] => INSERT INTO raghavan_Cms.Messages_tbl VALUES(5,'raghavan20','kannan','when is ur next increment','when do u expect to get ur next appraisal?','Yes','2005-06-16'); [29] => INSERT INTO raghavan_Cms.Messages_tbl VALUES(7,'raghavan20','raghavan20','try again','pls discard the message as its sent for trial purpose','Yes','2005-06-19'); [30] => INSERT INTO raghavan_Cms.Messages_tbl VALUES(9,'raghavan20','diviya','trial1','hi da','No','2005-06-21'); [31] => INSERT INTO raghavan_Cms.Messages_tbl VALUES(11,'raghavan20','raghavan20','message 4 ','again for trial','No','2005-06-23'); [32] => ','Yes','2005-06-23');
You can see it reads the' database create statement' and misses the immediate 'use database statement' and not able to read 'create table statements' but reads all 'insert statements'.

Now how do I read all these commands separately??? :roll:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<?php

ob_start();

?>
#
#http://www.yourresourcecenter.com Backup software
#DATE: 27-08-2005 12:43:42
#
#Database :raghavan_Cms
#
CREATE DATABASE `raghavan_Cms`;
USE `raghavan_Cms`;


#Blogs_tbl
CREATE TABLE `Blogs_tbl` (
  `BlogId` int(5) unsigned NOT NULL auto_increment,
  `MemberId` varchar(5) NOT NULL default '',
  `Title` varchar(50) NOT NULL default '',
  `Description` text,
  `Date` date NOT NULL default '0000-00-00',
  PRIMARY KEY  (`BlogId`)
) TYPE=MyISAM;

#
#raghavan_Cms.Blogs_tbl: Table data
#

INSERT INTO raghavan_Cms.Blogs_tbl VALUES(1,'M1003','Beautiful','blog on all the beautiful  places across the world!!!','2005-05-25');


#ChatMessages_tbl
CREATE TABLE `ChatMessages_tbl` (
  `Id` int(10) unsigned NOT NULL auto_increment,
  `ChatRoomId` int(11) unsigned NOT NULL default '0',
  `FromId` int(10) unsigned NOT NULL default '0',
  `RecipientId` int(11) unsigned default '0',
  `Time` timestamp(14) NOT NULL,
  `Message` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`Id`),
  KEY `ChatRoomId` (`ChatRoomId`)
) TYPE=MyISAM;

#
#raghavan_Cms.ChatMessages_tbl: Table data
#



#ChatRooms_tbl
CREATE TABLE `ChatRooms_tbl` (
  `Id` int(11) NOT NULL auto_increment,
  `Name` varchar(25) NOT NULL default '',
  `Description` varchar(100) default NULL,
  `MaxUsersAllowed` int(11) NOT NULL default '200',
  KEY `Id` (`Id`,`Name`,`MaxUsersAllowed`)
) TYPE=MyISAM;

#
#raghavan_Cms.ChatRooms_tbl: Table data
#

INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(1,'General Discussion','can talk about anything here',100);
INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(2,'Technology - Hardware','Can talk about hardware and networking',100);
INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(3,'Techonology - Software','Talk about any language, software or anything relevant to it',5);


#ChatUsers_tbl
CREATE TABLE `ChatUsers_tbl` (
  `Id` int(10) unsigned NOT NULL auto_increment,
  `ChatRoomId` int(10) unsigned NOT NULL default '0',
  `UserName` varchar(20) NOT NULL default '',
  `LastUpdate` timestamp(14) NOT NULL,
  `SessionId` varchar(32) default NULL,
  PRIMARY KEY  (`Id`),
  UNIQUE KEY `UserName` (`UserName`),
  KEY `ChatRoomId` (`ChatRoomId`)
) TYPE=MyISAM;

#
#raghavan_Cms.ChatUsers_tbl: Table data
#

INSERT INTO raghavan_Cms.ChatUsers_tbl VALUES(3,1,'Mini','20050826073821','df0aec64d22aa8808a449aac87af8483');


#Images_tbl
CREATE TABLE `Images_tbl` (
  `ImageId` varchar(5) NOT NULL default '',
  `Location` text NOT NULL,
  PRIMARY KEY  (`ImageId`)
) TYPE=MyISAM;

#
#raghavan_Cms.Images_tbl: Table data
#

INSERT INTO raghavan_Cms.Images_tbl VALUES('I1001','/images/avatars/000.gif');
INSERT INTO raghavan_Cms.Images_tbl VALUES('I1002','/images/avatars/001.gif');
INSERT INTO raghavan_Cms.Images_tbl VALUES('I1003','/images/avatars/002.gif');
INSERT INTO raghavan_Cms.Images_tbl VALUES('I1004','/images/avatars/003.gif');
INSERT INTO raghavan_Cms.Images_tbl VALUES('I1005','/images/avatars/004.gif');
<?php

$text = ob_get_clean();

preg_match_all('@^(?![\s#])\s*((?s:.*?))\s*;\s*$@m',$text,$matches);
print_r($matches);

?>
outputs

Code: Select all

Array
(
    [0] => Array
        (
            [0] => CREATE DATABASE `raghavan_Cms`;
            [1] => USE `raghavan_Cms`;


            [2] => CREATE TABLE `Blogs_tbl` (
  `BlogId` int(5) unsigned NOT NULL auto_increment,
  `MemberId` varchar(5) NOT NULL default '',
  `Title` varchar(50) NOT NULL default '',
  `Description` text,
  `Date` date NOT NULL default '0000-00-00',
  PRIMARY KEY  (`BlogId`)
) TYPE=MyISAM;

            [3] => INSERT INTO raghavan_Cms.Blogs_tbl VALUES(1,'M1003','Beautiful','blog on all the beautiful  places across the world!!!','2005-05-25');


            [4] => CREATE TABLE `ChatMessages_tbl` (
  `Id` int(10) unsigned NOT NULL auto_increment,
  `ChatRoomId` int(11) unsigned NOT NULL default '0',
  `FromId` int(10) unsigned NOT NULL default '0',
  `RecipientId` int(11) unsigned default '0',
  `Time` timestamp(14) NOT NULL,
  `Message` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`Id`),
  KEY `ChatRoomId` (`ChatRoomId`)
) TYPE=MyISAM;

            [5] => CREATE TABLE `ChatRooms_tbl` (
  `Id` int(11) NOT NULL auto_increment,
  `Name` varchar(25) NOT NULL default '',
  `Description` varchar(100) default NULL,
  `MaxUsersAllowed` int(11) NOT NULL default '200',
  KEY `Id` (`Id`,`Name`,`MaxUsersAllowed`)
) TYPE=MyISAM;

            [6] => INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(1,'General Discussion','can talk about anything here',100);
            [7] => INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(2,'Technology - Hardware','Can talk about hardware and networking',100);
            [8] => INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(3,'Techonology - Software','Talk about any language, software or anything relevant to it',5);


            [9] => CREATE TABLE `ChatUsers_tbl` (
  `Id` int(10) unsigned NOT NULL auto_increment,
  `ChatRoomId` int(10) unsigned NOT NULL default '0',
  `UserName` varchar(20) NOT NULL default '',
  `LastUpdate` timestamp(14) NOT NULL,
  `SessionId` varchar(32) default NULL,
  PRIMARY KEY  (`Id`),
  UNIQUE KEY `UserName` (`UserName`),
  KEY `ChatRoomId` (`ChatRoomId`)
) TYPE=MyISAM;

            [10] => INSERT INTO raghavan_Cms.ChatUsers_tbl VALUES(3,1,'Mini','20050826073821','df0aec64d22aa8808a449aac87af8483');


            [11] => CREATE TABLE `Images_tbl` (
  `ImageId` varchar(5) NOT NULL default '',
  `Location` text NOT NULL,
  PRIMARY KEY  (`ImageId`)
) TYPE=MyISAM;

            [12] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1001','/images/avatars/000.gif');
            [13] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1002','/images/avatars/001.gif');
            [14] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1003','/images/avatars/002.gif');
            [15] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1004','/images/avatars/003.gif');
            [16] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1005','/images/avatars/004.gif');

        )

    [1] => Array
        (
            [0] => CREATE DATABASE `raghavan_Cms`
            [1] => USE `raghavan_Cms`
            [2] => CREATE TABLE `Blogs_tbl` (
  `BlogId` int(5) unsigned NOT NULL auto_increment,
  `MemberId` varchar(5) NOT NULL default '',
  `Title` varchar(50) NOT NULL default '',
  `Description` text,
  `Date` date NOT NULL default '0000-00-00',
  PRIMARY KEY  (`BlogId`)
) TYPE=MyISAM
            [3] => INSERT INTO raghavan_Cms.Blogs_tbl VALUES(1,'M1003','Beautiful','blog on all the beautiful  places across the world!!!','2005-05-25')
            [4] => CREATE TABLE `ChatMessages_tbl` (
  `Id` int(10) unsigned NOT NULL auto_increment,
  `ChatRoomId` int(11) unsigned NOT NULL default '0',
  `FromId` int(10) unsigned NOT NULL default '0',
  `RecipientId` int(11) unsigned default '0',
  `Time` timestamp(14) NOT NULL,
  `Message` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`Id`),
  KEY `ChatRoomId` (`ChatRoomId`)
) TYPE=MyISAM
            [5] => CREATE TABLE `ChatRooms_tbl` (
  `Id` int(11) NOT NULL auto_increment,
  `Name` varchar(25) NOT NULL default '',
  `Description` varchar(100) default NULL,
  `MaxUsersAllowed` int(11) NOT NULL default '200',
  KEY `Id` (`Id`,`Name`,`MaxUsersAllowed`)
) TYPE=MyISAM
            [6] => INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(1,'General Discussion','can talk about anything here',100)
            [7] => INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(2,'Technology - Hardware','Can talk about hardware and networking',100)
            [8] => INSERT INTO raghavan_Cms.ChatRooms_tbl VALUES(3,'Techonology - Software','Talk about any language, software or anything relevant to it',5)
            [9] => CREATE TABLE `ChatUsers_tbl` (
  `Id` int(10) unsigned NOT NULL auto_increment,
  `ChatRoomId` int(10) unsigned NOT NULL default '0',
  `UserName` varchar(20) NOT NULL default '',
  `LastUpdate` timestamp(14) NOT NULL,
  `SessionId` varchar(32) default NULL,
  PRIMARY KEY  (`Id`),
  UNIQUE KEY `UserName` (`UserName`),
  KEY `ChatRoomId` (`ChatRoomId`)
) TYPE=MyISAM
            [10] => INSERT INTO raghavan_Cms.ChatUsers_tbl VALUES(3,1,'Mini','20050826073821','df0aec64d22aa8808a449aac87af8483')
            [11] => CREATE TABLE `Images_tbl` (
  `ImageId` varchar(5) NOT NULL default '',
  `Location` text NOT NULL,
  PRIMARY KEY  (`ImageId`)
) TYPE=MyISAM
            [12] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1001','/images/avatars/000.gif')
            [13] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1002','/images/avatars/001.gif')
            [14] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1003','/images/avatars/002.gif')
            [15] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1004','/images/avatars/003.gif')
            [16] => INSERT INTO raghavan_Cms.Images_tbl VALUES('I1005','/images/avatars/004.gif')
        )

)

[edit] added a quick change to the regex to make it allow whitespace before the commands (just in case)
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Thats awesome mate...thanks very much.
But I really need to understand wot you have done here

'@^(?![\s#])((?s:.*?))\s*;\s*$@m'

@@ - delimiters
^ - start of search string
$ - end of search string
(?![\s#])
? followed by ! - does it mean the following characters should not come in the search string???
[\s#] - looking for space or a '#'
((?s:.*?))
?s: - I dont find this syntax in the tutorials I read
.*? - lazy greed match which we talked yesterday
\s*; - allows any number of spaces before a semicolon which is the terminator of each statement
\s* - there can be any number of statements before the end of the search string

I dont know why you are dealing with output buffering??? do you suspect there might be problems with reading large chunk of data???totally confused :roll:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

(?![\s#]) is a negative look ahead. It requires that the next character not be a space or # character
(?s:) is a mode switch. It turns on single string mode. We explained it in detail here
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

Post by visonardo »

there is a project called "bigdump", search in google if you want know more, perhaps it will help you so much

http://www.ozerov.de/bigdump.php
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

18 month old thread. Let it die.
Post Reply