Search code examples
phpfilestoragemediadisk

How to remove space if is after a slash in php


Example:

/var/www/media/ Book 1 Chapter 1 - Video 1 Part 1

to become

/var/www/media/Book 1 Chapter 1 - Video 1 Part 1

Solution

  • So assuming that this spacing is a result of this concatenation:

    "/var/www/media/" . $filepath

    Then the issue is with the $filepath variable. You can fix it by simply using the PHP trim() function to remove whitespace before and after the string.

    Before: " This is my string. "

    After: "This is my string."