Page 1 of 1

Regular Expressions Question

Posted: Mon Oct 15, 2007 2:33 pm
by junestag
I'm trying to format a variable using regular expressions. I'm new to regular expressions and am having some difficulty. When I upload my file with the code given below it doesn't work (blank page). Please take a look at the code and let me know what I'm doing wrong:

Code: Select all

$coursebrief = strtolower($row['subject'].[_]*.[a-z]*.[_]*.$row['coursenum'].[_]*.$row['section']'.pdf');
As you can see I'm trying to set the variable $coursebrief to a string (later to be used to match a filename) that has various formats. Is it possible to apply a regular expression in this way?

thanks!
sage

Posted: Mon Oct 15, 2007 4:03 pm
by Christopher
You might want to try;

Code: Select all

$coursebrief = strtolower("{$row['subject']}.[_]*.[a-z]*.[_]*.{$row['coursenum']}.[_]*.{$row['section']}.pdf");
It is not clear to me whether you are using the .'s for concatenating or as regex wildcards?

concat

Posted: Mon Oct 15, 2007 4:24 pm
by junestag
the dots are for concatenation :)

mmm, still not working...

Posted: Mon Oct 15, 2007 5:03 pm
by junestag
And I tried the code change you suggested with the {} and the page is still showing up blank. I tried taking that code out of the page and it worked fine, so I know the problem is in that line somewhere.

thanks again!
sage

Posted: Mon Oct 15, 2007 5:23 pm
by Christopher
Well you need quotes around any string literals, so if you are concatenating it would be;

Code: Select all

$coursebrief = strtolower($row['subject'] . '[_]*.[a-z]*.[_]*' . $row['coursenum'] . '[_]*' . $row['section'] . 'pdf');

Posted: Mon Oct 15, 2007 6:32 pm
by RobertGonzalez
Two things that would help you in the long run:

1) Set up a local server and develop there.
2) Develop with display_errors on and with error_reporting set to E_ALL.

Posted: Wed Oct 24, 2007 11:54 am
by junestag
thanks everyone! :P