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
  • #240539

    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.



    You should really be looking in the PHP manual for a description and examples that illustrate how the function works:

    Or you may find this slightly easier to understand:


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

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



    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.


    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
    A Noun

    Variable example:
    $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:

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

    Curly braces = Complex (curly) syntax:

    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 { }. 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.