I’ll explain the entire line broken up into their own parts
The following checks if post_content is available as a key inside $var (which is an array)
<?php if($var['post_content']): ?>
I’m going to do this explanation from the inside out, as that is how it will be processed by PHP
The preg_replace will find ALL […] where there is an opening [ and a closing ] with ANY text in between (There are \ in front of [ and ] because those are special characters to regex and they must be escaped (otherwise they would be considered holding a range of acceptable/unacceptable characters). It will replace all instances of […] found in $var[‘post_content’] with an empty string.
The output of that replacement is then sent to strip_tags which removes ALL HTML and PHP tags from the output of preg_replace (remember preg_replace only removed shortcodes). After removing all tags the output is sent to substr.
substr takes the output of strip_tags and only grabs the first 200 characters. The 0 represents where to start in the string (so we are starting at the beginning of the string, and 200 is how many characters you want to grab AFTER (and including) that starting position. It’s output is then sent to echo which writes the final result to the screen.
<?php echo substr(strip_tags(preg_replace('/\\[.*?\\]/', '', $var['post_content'])), 0, 200); ?>...
Closes the if statement that was opened at the beginning
<?php endif; ?>
Okay, so let’s do an example, let’s say $var[‘post_content’] contains the following value:
[noparse]This is a test that I created for a <a href="sitepoint.com">sitepoint</a> question, it was answered [b][i]quickly[/i][/b]! I need a lot more text to make this over 200 characters so I'm just going to keep typing random words until that limit is passed by so this can be shown correctly.[/noparse]
When it processes through preg_replace, the output of preg_replace will be
This is a test that I created for a <a href="sitepoint.com">sitepoint</a> question, it was answered quickly! I need a lot more text to make this over 200 characters so I'm just going to keep typing random words until that limit is passed by so this can be shown correctly.
That phrase then gets passed into strip_tags, and when strip_tags is done, the phrase will look like
This is a test that I created for a sitepoint question, it was answered quickly! I need a lot more text to make this over 200 characters so I'm just going to keep typing random words until that limit is passed by so this can be shown correctly.
Then substr will receive the above phrase and take the first 200 characters which will be:
This is a test that I created for a sitepoint question, it was answered quickly! I need a lot more text to make this over 200 characters so I'm just going to keep typing random words until that limit
Then echo writes out that phrase and the ‘…’ gets appended because it is behind the echo statement. So your final output
This is a test that I created for a sitepoint question, it was answered quickly! I need a lot more text to make this over 200 characters so I'm just going to keep typing random words until that limit...