tooth-paste Posted August 30, 2018 Posted August 30, 2018 I'am using the file field type. To output the name I use $file->name. The problem is when I upload a file with a no breaking space, an underscore is added. Name of the file.pdf Becomes Name_of_the_file.pdf How can I remove the underscore?
tooth-paste Posted August 30, 2018 Author Posted August 30, 2018 6 minutes ago, Soma said: $name = str_replace("_", "", $file->name); Do you mean like this? It does not work. $files = $pages->get("/portal/")->portal_file; $name = str_replace("_", "", $file->name); foreach ($files as $file) { echo '<div class="row"> <div class="col-md-12"> <a href="'. $file->url .'">'. $name .'</a><br /> </div> </div>'; }
adrian Posted August 30, 2018 Posted August 30, 2018 That replacement needs to be inside the foreach. You probably also want to replace with " " instead of "" 1
Soma Posted August 30, 2018 Posted August 30, 2018 Also I wouldn't use "$files" as that is a PW template variable. https://processwire.com/api/ref/files/ 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now