zohab Posted January 10, 2012 Share Posted January 10, 2012 Hi, I am able to parse php variable in double quote but not in single quote. How can I parse in single quote. Following example shows 2 results and I want same result in both. First Name : Zohaib First Name : $firstname // Connecting, selecting database $link = mysql_connect('localhost', 'root', 'password'); mysql_select_db('dbname'); // Performing SQL query $query = 'SELECT first_name FROM tablename'; $result = mysql_query($query); // Printing results in HTML while ($row = mysql_fetch_assoc($result)) { $firstname=$row['first_name']; } echo"<table> <tr> <td>First Name : </td> <td>$firstname</td> </tr></table>"; echo'<table> <tr> <td>First Name : </td> <td>$firstname</td> </tr></table>'; What are the changes I need to do to achieve same result. Any solution ? - Thanks. Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 10, 2012 Share Posted January 10, 2012 That is the expected behavior for PHP. There are four different methods of defining strings in PHP: single quoted, double quoted, heredoc syntax & nowdoc syntax. Only in the double quoted and heredoc methods are variables parsed. Also, special escape sequences for things such as tabs (\t) and new lines (\n) will be parsed. See the documentation here: php.net/manual/en/language.types.string.php Quote Link to comment Share on other sites More sharing options...
zohab Posted January 10, 2012 Author Share Posted January 10, 2012 Thanks I am able to parse variables using heredoc Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.