I’m trying to do this
<?php echo cleanFileName({file_name}); ?>in a template, but EE appears to choke on it.
Notes:
1. I’m using Mark Hout’s “File” extension (http://docs.markhuot.com/ee/extensions/file)
2. Php is enabled in this template on the Output stage
3. I’ve used php to include() my function
The “File” extension simply outputs a filename (if it’s not an image), so the purpose of the cleanFileName() function is to A) remove the file extension, B) replace underscores with spaces, and C) ucwords() the modified string.
function cleanFileName($string) {
// remove file extension
$new_string = substr($string, 0, strrpos($string, '.'));
// convert underscores to spaces
$new_string = str_replace('_', ' ', $new_string);
// uppercase words
$new_string = ucwords($new_string);
return $new_string;
}This works
<?php
// outputs "Some Sample String"
echo cleanFileName('some_sample_string.pdf');
?>but the system chokes when I try to pass {file_name} to my function.
Notice: Use of undefined constant Membership_Awards - assumed ‘Membership_Awards’ in /[basepath]/system/core/core.functions.php(637) : eval()‘d code on line 26
Notice: Use of undefined constant pdf - assumed ‘pdf’ in /[basepath]/system/core/core.functions.php(637) : eval()‘d code on line 26
It looks like the file name is getting in there somehow, but EE doesn’t know what to do with it?
Am I missing something? I poured over the forums before making this post, so my apologies if this issue has already been adressed.