PHP single quotes, double quotes and concatenation / variable eval in PHP
- Written By
- bos
- Submitted At
- 2009-10-30 15:12:33
- Num Views
- 991
- Category
- PHP
|
A simple question. I have just started playing with php and have a few folders in my wwwroot with examples. I am now creating a php index page that reads the folder names and list them as url's So I do: $folders = (glob("*",GLOB_ONLYDIR)); then I want to add each of the folder names into a url something like: foreach ($folders as $folder){ print '<br>'; print '<a href="$folder">$folder</a><br>'; print '<br>'; }//end foreach How do i get the variable $folder into the url? Is there a function to concatenate them? tx, Dawie By bos @ 2009-10-30 15:12:33
|
|
I see what you are doing. A good html editor with syntax highlighting might help you overcome the basic syntax issues you are going to experience in the beginning. I recommend notepad++ download the file: npp.5.5.1.Installer.exe , small but extremely versatile. Try the following: foreach ($folders as $folder){ print '<br>'; print '<a href="'.$folder.'">'.$folder.'</a><br>'; print '<br>'; }//end foreach If you use single quotes, everything is seen as literal If you use double quotes, php still goes and converts variables into their values before returning the string. Example 1: $test = 'abc'; echo 'This is a $test'; Result will be: This is a $test Example 2: $test = 'abc'; echo "This is a $test"; Result will be: This is a abc By PHPin24 @ 2009-10-30 16:54:19
|
|
:-) cool, thanx. You've just smoothed a few of my hurdles :-) By bos @ 2009-10-30 17:53:09
|
|
Great! That's why we're here. By PHPin24 @ 2009-10-30 18:22:27
|
|
so all iI need to add now is a classes that do the same with files, and some that use reg ex on the files and their functions/classes and we've got the makings of a framework ;- ) By bos @ 2009-10-30 20:09:54
|
