Regular Expressions Question

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
junestag
Forum Commoner
Posts: 39
Joined: Tue Sep 18, 2007 5:14 pm
Location: Alaska
Contact:

Regular Expressions Question

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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?
(#10850)
junestag
Forum Commoner
Posts: 39
Joined: Tue Sep 18, 2007 5:14 pm
Location: Alaska
Contact:

concat

Post by junestag »

the dots are for concatenation :)
junestag
Forum Commoner
Posts: 39
Joined: Tue Sep 18, 2007 5:14 pm
Location: Alaska
Contact:

mmm, still not working...

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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');
(#10850)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
junestag
Forum Commoner
Posts: 39
Joined: Tue Sep 18, 2007 5:14 pm
Location: Alaska
Contact:

Post by junestag »

thanks everyone! :P
Post Reply