Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End php code explanation

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #240539
    zaahideen
    Participant

    im quite new to php coding and still learning. just wanted some explanation on a line of coding:

    $content = str_ireplace ( '{user_name}', $sale->user->name, $content );

    could some one please break up the different parts of this code and explain what they mean.

    thanks

    #240542
    Beverleyh
    Participant

    You should really be looking in the PHP manual for a description and examples that illustrate how the function works: http://php.net/manual/en/function.str-ireplace.php

    Or you may find this slightly easier to understand: http://www.w3schools.com/php/func_string_str_ireplace.asp

    #240625
    zaahideen
    Participant

    ok thanks but what does $content refer to? is it a field in the database?

    also what does $sale->user->name refer to?

    thanks

    #240642
    Beverleyh
    Participant

    Don’t know – it’s your website.
    Look at the code to see where the variables originate – maybe there are comments that explain. Or is there documentation to refer to? Or try echoing it out to see what the variables print. I would expect that their naming conventions will correspond to something logically related in your database.

    #240779
    I.m.learning
    Participant

    Anything that begins with a dollar sign is a variable. From your example, $content is being used as a recursive code

    To explain recursive, if you don’t already know:
    PHP is recursive; it stands for PHP: Hypertext Preprocessor

    Another example is the name BRIAN as a recursive acronym
    Brian
    Really
    Is
    A Noun

    Variable example:
    <?php
    $txt = “Hello world!”;
    echo $txt;
    ?>

    The result is: Hello world!

    The forward arrow is used when referring to the attributes of an instantiated object.

    This calls a function:
    $variable->my_function();

    This accesses a property:
    $variable->name = ‘property’;

    Curly braces = Complex (curly) syntax:

    http://php.net/manual/en/language.types.string.php#language.types.string.parsing.complex

    Any scalar variable, array element or object property with a string representation can be included via this syntax. Simply write the expression the same way as it would appear outside the string, and then wrap it in { }.

    PHP.net is a really confusing site for some explanations; however, there are always examples to view for a visual aid.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.