treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Php Functions

  • Hi Everyone

    I need some help, Im trying to echo a function and It doesnt work, is it possible? If so how?

    eg:
    <?php echo \"http://getUrl()\"; ?>


    All it does is shows

    http://getUrl() in the address bar

    Thanks In advance

    jonleesmith
  • Something like this should work.

    <?php 
    $url = getUrl();
    echo \"http://\".$url;
    ?>


    Basically you are trying to echo a function call within a string, which is impossible as it is treating the function call like the string.

    I'm not sure if the following also works but you could try

    <?php 
    echo \"http://\".getURL();
    ?>
  • Does'nt seem to be working unfortunately. Gota be some how
    $query = \"SELECT title FROM go_pages \";

    $result = mysql_query($query);


    while ($row = mysql_fetch_array($result)) {
    echo \"<li><a href='/content/?p=$row[title]'>$row[title]</a></li>\";



    I want to put the getUrl() function in
    <a href='_here_/content/ .......etc etc


    Id really appreciate any other suggestions i did try

    \" . getUrl() . \"
    but that didnt work either
  • Enclose your complex variables in curly braces and you should be fine.

    echo \"<li><a href='/content/?p={$row[title]}'>{$row[title]}</a></li>\";
  • This is the exact way to use a echo into the PHP Language,
    <?php
    $myString = "Hello!";
    echo $myString;
    echo "<h5>I love using PHP!</h5>";
    ?>