Search code examples
phpjoomlajoomla2.5

two types of directory separators in joomla


while debugging in JPath::find, my $path variable attain a value which is a mixture of directory separators. Half are back slashes and half are forward slashes. why is this so??

C:\Users\arslan\Desktop\xampp-win32-1.8.1-VC9\xampp\htdocs\COM/components/com_hello/views/pendingHello/tmpl

Solution

  • Windows uses back slashes \ and linux/mac (all unix based) use forward slashes / for the directory separator normally. Within PHP, either one actually works, as well as a mix like you see.

    There is a constant in PHP called DIRECTORY_SEPARATOR which has the correct slash for your OS. However, when creating a path this isn't typically necessary, because Windows will still process what you have correctly.

    So, the short answer is that / is used within the component which works fine no matter where Joomla is installed; however the first part of the path is system generated and Windows will always generate the path with \.

    You can see a bit more on this here: http://alanhogan.com/tips/php/directory-separator-not-necessary