I need this: $variable = if variable has a value echo it, else echo default value. How can I code that in php?
Shouldn't it be another way round? echo (strlen($variable) == 0) ? 'default' : $variable; PHP: or simply echo ($variable == '') ? 'default' : $variable; PHP:
To get a variable from a url, just use the following example, pretending that the URL is mysite.com?var=somevar $var = $_GET['var']; echo $var; Code (markup): That code would echo "somevar" on the page. Also remember to sanitize any input before doing anything with it in the script.
Another way to check whether variable is empty or not $name="adeel fakhar"; if(empty($name)) { echo "variable is empty"; } else{ echo $name; }
Dear Fracisc you can set any variable in url like this <?php $name="Adeel Fakhar"; ?> <a href="http://site.com?name=<?php echo $name;?">Click Here</a>