As I understand it, the site will be created without using a framework? And then the developers I knew were buzzing all over my ears that I needed to study the Yii framework.

2) I wanted to ask... An example of creating an online store, which is discussed in the course, is it rather academic? Real commercial projects are probably created using frameworks, because... this greatly optimizes the development process through the use of standard code templates. The answer to this question would help clarify what is happening... PHP Start | Is it still worth doing the practice in order to understand the general logic?

Answer:

1) Friends, this is correct, I think so too. But any framework requires preparation, for example, knowledge. When I built an MVC system in practice, I tried to follow the approaches that are used in frameworks. Therefore, PHP Start (theory and practice) will help with preparation, after which you can safely start learning yii2 (or something similar).

Project repository address:

Question #1:

I can't get rid of the error:

Notice: Use of undefined constant _FILE_ - assumed "_FILE_" in /Users/Elios/Sites/Test/index.php on line 10

Tell me, what could it be?

Answer:

Before and after FILE you need to write 2 characters _

__FILE__ belongs to the "magical" PHP constants. More details here.

PHP provides several functions that search for one string within another. Some return the location of the found string (strpos , strrpos and related), and return part of the original string (strstr and strrchr). The search functions return false if the string you are searching for is not found within the original.

If your goal is simply to determine whether one string exists within another, the most efficient option is strpos .

strpos

The strpos function searches its first string argument for its second and returns the zero-based index location of the first match within the string, or false if it is not found. The following example demonstrates:

$str = ; // search for the first occurrence of "need" within $str$pos = strpos($str, "need"); // display type and value of $pos var_dump ($pos) ; // int(3)

Although we demonstrated the result using var_dump above, a typical examination of the return value for strpos is performed as follows:

// how to inspect strpos return value ($pos) if ( $pos !== false ) ( // if search string found echo "found it at location $pos" ; ) else ( echo "not found." ; )

Be sure to use the === or !== operators to compare the strpos function"s return value to false . If the substring is found at the start of the string, strpos will return 0 , which the == or != operators would convert to false .

You can specify an offset to begin the search a specified number of characters from the start of the string, as this example demonstrates:

/* strpos arguments: * subject string (aka haystack), search string (needle), offset (optional) */ // start search for "need" from character 10 in $str$pos = strpos ($str , "need" , 10 ) ; // 20

When starting the search from character 10 , the result is 20 , the index location of the start of the word needle .

strrpos

The strrpos function finds the position of the last occurrence of a substring in a string:

// example string to use for searches$str = "We need to find the needle in the haystack."; // find location of last occurrence of "need" in $str$pos = strrpos ($str , "need" ) ; // 20

The strrpos function also provides an optional offset parameter which can be either positive or negative. If the offset is positive, that number of characters at the beginning of the string will be excluded from the search. Consider the following example:

// search from right for "We" excluding first 3 characters$pos = strrpos ($str , "We" , 3 ) ; var_dump ($pos) ; //bool(false)

The result is false since "We" is not found when the search excludes the first three characters.

If the offset is negative, that many characters at the end of the string are excluded from the search. We demonstrate with two searches specifying a negative offset:

// search from right for "hay" excluding last 5 characters$pos = strrpos ($str , "hay" , - 5 ) ; // int(34) // search from right excluding last 10 characters$pos = strrpos ($str , "hay" , - 10 ) ; //bool(false)

The last result above is false since "hay" is not found when the search excludes the last 10 characters.

Notice that the return value of the strrpos function gives the location from the start of the string, even though the search commences from the right.

stripos and stripos

The strpos and strrpos functions perform case-sensitive searches. PHP provides stripos and strripos functions to perform case-insensitive searches. They work just like their case-sensitive equivalents:

// example string to use for searches$str = "We need to find the needle in the haystack."; // do case-insensitive search for "we"$pos = stripos($str, "we"); // int(0) // do case-insensitive search from right for "Need"$pos = strripos($str, "Need"); // int(20)

The case-insensitive search for "we" results in 0 , indicating it was found at the beginning of the string we are searching in. The case-insensitive search for "Need" from the right (using strripos), finds it at location 20 .

strstr

The strstr function searches the first string argument for the second. If the second is found within the first, strstr returns the portion of the original string starting from the first found occurrence to the end of the string.

// example string $str = "We need to find the needle in the haystack."; // search for "the" in $str $newstr = strstr ($str , "the" ) ; var_dump ($newstr) ; // string(27) "the needle in the haystack."

The strstr function returns the first "the" it finds, along with the rest of the original string.

If you pass true as the third argument to strstr , the portion of the original string before the found string is returned:

// pass true to return the part of $str before "the"$newstr = strstr ($str , "the" , true ) ; var_dump ($newstr) ; // string(16) "We need to find "

This time the strstr function returns everything before the first "the" in the string.

PHP also provides the stristr function which works exactly the same as strstr except that it performs a case-insensitive search.

strhrchr

The strrchr function searches the first string argument from the right for the character we specify in the second argument. The function returns the portion of the string from the location of the found instance of that character to the end of the string:

// example string $str = "We need to find the needle in the haystack."; // search from right for "s" in $str$newstr = strstr ($str , "s" ) ; var_dump ($newstr) ; // string(6) "stack."

Notice that unlike strstr , if the second argument consists of multiple characters, only the first is used:

// test with multi-character second argument$newstr = strrchr ($str , "the" ) ; var_dump ($newstr) ; // string(5) "tack."

Instead of returning "the haystack" , the strrchr function returns "tack" , applying only the first letter of the second argument to the search.

(PHP 4, PHP 5, PHP 7)

ob_start — Enable output buffering

Description

Bool ob_start ([ callable $output_callback = NULL [, int $chunk_size = 0 [, int $flags = PHP_OUTPUT_HANDLER_STDFLAGS ]]])

This function enables output buffering. If output buffering is active, script output is not sent (except for headers), but is stored in an internal buffer.

The contents of this internal buffer can be copied to a string variable using ob_get_contents() . To output the contents of the internal buffer you should use ob_end_flush() . Alternatively you can use ob_end_clean() to destroy the contents of the buffer.

Attention

Some web servers (for example Apache) change the working directory of the script when the callback function is called. You can get it back using chdir(dirname($_SERVER["SCRIPT_FILENAME"])) in the callback function.

Output buffers are pushed onto the stack, meaning calls are allowed ob_start() after calling another active ob_start(). In this case it is necessary to call ob_end_flush() the appropriate number of times. If multiple callback functions are active, the output is filtered sequentially for each of them in nesting order.

List of parameters

An optional output_callback parameter can be specified. This function takes a string as an argument and must also return a string. It is called when a reset (send) or cleanup (using ob_flush() , ob_clean() or similar functions) or if the output buffer is flushed to the browser at the end of the request. When the output_callback function is called, it receives the contents of the buffer and must return the updated contents for the output buffer to be sent to the browser. If output_callback is not a valid function, then the documented function will return FALSE. Function description for this parameter:

String handler (string $buffer [, int $phase ])

Buffer Contents of the output buffer. phase Bit mask of constants PHP_OUTPUT_HANDLER_*.

If output_callback returns FALSE, then the original information will be sent to the browser without changes.

The output_callback parameter can be ignored by passing the value NULL.

ob_end_clean() , ob_end_flush() , ob_clean() , ob_flush() And ob_start() cannot be called from callback functions, since their behavior is unpredictable. If you want to delete the contents of the buffer, then return "" (an empty string) from the callback function. You also can't call functions print_r($expression, true) or highlight_file($filename, true) from output buffering callback functions.

Comment:

In PHP 4.0.4 the function ob_gzhandler() was introduced to make it easier to send gz-encoded data to web browsers that support compressed web pages. ob_gzhandler() determines the content encoding type accepted by the browser and returns output accordingly.

chunk_size

If the optional chunk_size parameter is passed, the buffer will be flushed after any output greater than or equal to chunk_size in size. Default value 0 means that the output function will be called when the buffer is closed.

Before PHP 5.4.0, value 1 was a special value that set the parameter chunk_size at 4096.

The flags parameter is a bitmask that controls the operations that can be performed on the output buffer. By default, it allows the output buffer to be flushed, flushed, and deleted, which is the same as | | , or PHP_OUTPUT_HANDLER_STDFLAGS as an abbreviation for this combination.

Each flag controls access to a set of functions, as described below:

Constant Functions
PHP_OUTPUT_HANDLER_CLEANABLE ob_clean() , ob_end_clean() , And ob_get_clean() .
PHP_OUTPUT_HANDLER_FLUSHABLE ob_end_flush() , ob_flush() , And ob_get_flush() .
PHP_OUTPUT_HANDLER_REMOVABLE ob_end_clean() , ob_end_flush() , And ob_get_flush() .

Return values

Returns TRUE upon successful completion or FALSE in case of an error.

List of changes

Version Description
7.0.0 If ob_start() used inside the output buffer callback function, this function will no longer generate an error E_ERROR, but will instead call E_RECOVERABLE_ERROR, allowing third party error handlers to catch it.
5.4.0 Third parameter ob_start() changed from boolean ( boolean ) of the erase parameter (which, when set to FALSE prevented the buffer from being deleted until the script completed) to an integer ( integer ) flags parameter. Unfortunately, this means API incompatibility for code that used the third parameter before PHP versions 5.4.0. Look example with flags, to understand how to work with the code so that it maintains compatibility with both versions.
5.4.0 Parameter chunk_size, installed in 1 , now results in 1 byte being output to the output buffer.
4.3.2 The function will return FALSE in case output_callback cannot be executed.

Examples

Example #1 Example of a user-defined callback function

Function callback ($buffer)
{
// replace all apples with oranges
return (str_replace("apples", "oranges", $buffer));
}

Ob_start("callback");

?>


It's like comparing apples and oranges.






ob_end_flush();