bcarl314
02-05-2003, 10:01 PM
I'm trying to use the preg_match function but can't get it to work right.
The variable $nFile will contain a string which is a path to a file pulled from a DB. (ex: ./docs/myfile.doc)
Since the file can either be a .doc or a .pdf, I want to check if its a .doc and make the header for the document application/msword and make it application/pdf otherwise.
My code is below.
if(preg_match("/*.doc/",$nFile)) {
print "DOC";
}
else {
print "NOT DOC";
}
it gives me this error message:
Warning: Compilation failed: nothing to repeat at offset 0 in c:\dreamweaver\chapters\shownewsletter.php on line 15
I've also tried
if(preg_match("/*.doc/",$nFile,$matches)) {
print "DOC";
}
else {
print "NOT DOC";
}
Any help, along with a better explaination than the documentation provided from php would be a great help.
Thanks
The variable $nFile will contain a string which is a path to a file pulled from a DB. (ex: ./docs/myfile.doc)
Since the file can either be a .doc or a .pdf, I want to check if its a .doc and make the header for the document application/msword and make it application/pdf otherwise.
My code is below.
if(preg_match("/*.doc/",$nFile)) {
print "DOC";
}
else {
print "NOT DOC";
}
it gives me this error message:
Warning: Compilation failed: nothing to repeat at offset 0 in c:\dreamweaver\chapters\shownewsletter.php on line 15
I've also tried
if(preg_match("/*.doc/",$nFile,$matches)) {
print "DOC";
}
else {
print "NOT DOC";
}
Any help, along with a better explaination than the documentation provided from php would be a great help.
Thanks