RegExp question - what's allowed?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

RegExp question - what's allowed?

Post by Chris Corbyn »

Hi,

I want to slap a variable in the middle of my RegExp... the only thing is, the variable contains a forward slash and I'm not sure if it's messing up my code?

I keep getting this error
Warning: Unknown modifier 'a' in C:\Webs\email\app\index.php on line 72
when running this regExp

Code: Select all

$default_path = 'netscape/mail/'; //Testing with this assignment

foreach ($mailboxes as $v) {
	preg_match('/^\{.*\}'.$default_path.'(.+)$/',$v,$mailbox); // LINE 72!!! Remove server from mailbox string
	if (isset($mailbox[1])) {
		echo '<tr><td class="folderlist" style="border-bottom:1px dashed #F73B36"><b>&nbsp;&nbsp;&nbsp;&nbsp;<a class="folderlist" href="?mail_folder='.$mailbox[1].'">'.$mailbox[1].'</a></b></td></tr>';
	}
}
Any hints/clues?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

After some experimenting I found that it was the / which killed it.

I used

Code: Select all

$folder_exp = str_replace('/','\/',$default_path);
foreach ($mailboxes as $v) {    
    preg_match('/^\{.*\}'.$folder_exp.'(.+)$/',$v,$mailbox); // LINE 72!!! Remove server from mailbox string    
    if (isset($mailbox[1])) {        
        echo '<tr><td class="folderlist" style="border-bottom:1px dashed #F73B36"><b>&nbsp;&nbsp;&nbsp;&nbsp;<a class="folderlist" href="?mail_folder='.$mailbox[1].'">'.$mailbox[1].'</a></b></td></tr>';   
    }
}
and it started working.

Still not sure what the error means by unknown modifier 'a'..... what's 'a'?

:-D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the a in "mail" m is a known modifier.. a isn't.. :)
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

you may want to take a look at
[php_man]preg_quote[/php_man]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Thanks guys
Post Reply