- This topic is empty.
-
AuthorPosts
-
April 14, 2016 at 2:59 am #240539zaahideenParticipant
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
April 14, 2016 at 5:00 am #240542BeverleyhParticipantYou 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
April 16, 2016 at 2:23 am #240625zaahideenParticipantok thanks but what does
$content
refer to? is it a field in the database?also what does
$sale->user->name
refer to?thanks
April 16, 2016 at 12:52 pm #240642BeverleyhParticipantDon’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.April 20, 2016 at 1:03 pm #240779I.m.learningParticipantAnything 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 PreprocessorAnother example is the name BRIAN as a recursive acronym
Brian
Really
Is
A NounVariable 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.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.