Provide zblog template_zblog them_wordpress template download and customization

How does zblog intercept a summary with a specified number of words? Introduction to the custom interception method of zblog summary

Tianxing Studio 2024-02-29 19:43 Zblogphp Tutorial three hundred and sixty-one 0 Comments

zblog How to intercept a summary with a specified number of words? This article introduces the method of custom interception of zblog summary.

Zblog has a built-in function "SubStrUTF8" to intercept strings. The function is used as follows:

 SubStrUTF8 ('string ',' 20 ')// The function has two parameters. The first parameter is the string to be intercepted, and the second parameter is the number of characters to be intercepted

stay Zblog template The file can be used as follows:


The above "$article ->Intro" is the article summary, and other callable fields of the article are as follows:

 How does zblog intercept a summary with a specified number of words? Introduction to zblog summary custom interception method zblog custom zblog function zblog summary zblogphp tutorial page 1

PS: In the above method, you may encounter html code or spaces or other non text content in the article summary, resulting in output dislocation. Therefore, you need to filter the string first and then remove the spaces, so the final code is as follows:

 preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(TransferHTML($article->Intro, '[nohtml]'),20)));

The "TransferHTML" function in the above code is used to filter the html code, and the "preg_replace" function is used to remove spaces by regular matching. Finally, the specified number of article summaries and article contents can be output perfectly.

Can't find a tutorial that can solve your problem?

You can try to search or ask questions directly online. We also provide charging technical support. If you need it, you can contact us online.

Online questions Online Service

welcome you Comment: Cancel Reply

 Please fill in the verification code
  • Latest articles
  • Hot article ranking
  • Most Comments
Label aggregation
  • Sign in
  • Registered account Forgot your password?
  • register
  • Already have an account? Direct login Forgot your password?
  • Social account login