0

How to use an asterix as a wildcard operator in a path, without being a comment tag, its commenting out the rest of my code in the variable below, after '/*'

$dir = array("/www/home/wwwroot/*");
Vasko
  • 257
  • 3
  • 13

2 Answers2

2

use " or ' for string

$dir = array('/www/home/wwwroot/*');

interesting reading What is the difference between single-quoted and double-quoted strings in PHP?

Community
  • 1
  • 1
Simone Nigro
  • 4,717
  • 2
  • 37
  • 72
2

It's because of the quotes you are using. You can use ", but it's good practice in my opinion to use single quotes if you do not want to evaluate any variables inside the string:

$dir = array('/www/home/wwwroot/*');
James Waddington
  • 2,894
  • 2
  • 15
  • 24
  • shouldn't he use double quotes so that the `*` expands to the list of elements in the directory? – fedorqui Jan 24 '15 at 13:02
  • 1
    It's a string @fedorqui, what would be the point? Single quotes are (very, very) marginally quicker than double quotes. If you don't need to interpolate, using single quotes is usually the advice – Clive Jan 24 '15 at 13:04
  • @Clive ok it makes sense. I somehow was seeing it from the UNIX perspective and seeing any `*` as something that will get expanded when using, hence the need of `"` to fulfill it. But as you say, it is just a string. – fedorqui Jan 24 '15 at 13:06
  • Ah ok, yeah as far as PHP is concerned that's still a string, the `*` doesn't get replaced by the language – Clive Jan 24 '15 at 13:06
  • Why was I down voted for this question and closed as off-topic, the syntax that I used originally gave me an issue that i needed help to fix and I am grateful for the help that was given and solved my issue. The problem that caused this was the use non standard double quotes. Its a good lesson for newbies!!! since this question was closed off I can no longer ask question here on my account. I have reworded it, I even tried to delete this question but nothing. fixed one issue caused another, Thanks guys!! – Vasko Mar 10 '16 at 16:59
  • Maybe try to use the same standards that are strictly implemented for asking questions ON answering and commenting as well!!! then everyone will get banned from participating! – Vasko Mar 10 '16 at 17:13