Page 1 of 1

RegExp question - what's allowed?

Posted: Thu Dec 30, 2004 7:22 pm
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?

Posted: Thu Dec 30, 2004 7:57 pm
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

Posted: Thu Dec 30, 2004 8:31 pm
by feyd
the a in "mail" m is a known modifier.. a isn't.. :)

Posted: Fri Dec 31, 2004 12:25 am
by rehfeld
you may want to take a look at
[php_man]preg_quote[/php_man]

Posted: Fri Dec 31, 2004 2:22 am
by Chris Corbyn
Thanks guys