


As we all know, the WeChat applet cannot parse HTML tags after being compiled. So the question arises: How can the articles with pictures and texts edited through the WYSIWYG editor in the background be displayed on the WeChat applet? This is what this article is about.
The content of this article is as follows
1. How to parse HTML
2. How to display the mini program
3. Summary
The content discussed in this article is based on the cooperation of PHP and WeChat applet. The general idea is to use PHP to match the type, style and content of the tag, and then use the mini program to generate the tags that come with the mini program based on the tag type. For example, the P tag is converted to a view tag, the label tag is converted to a text tag, and the img tag is converted to an image tag. Then attach the content and style.
1. How to parse HTML
The article edited through the WYSIWYG editor looks like this (click "View Source" in the editor to view):
You can see that there are p tags, picture tags, line break tags, etc. These tags are directly passed to the mini program and displayed as they are. , cannot be parsed. At this time, you need the help of regular expressions. Commonly used regular expressions are as follows:
Other tags are similar, so I won’t give examples one by one.
PHP’s regular matching function is used as follows:
$view[1] in the above picture is the HTML of the article content or a certain paragraph HTML inside the tag.
Other regular expressions are used similarly. The data format returned to the front end is as follows:
2. The applet displays
small The program logic is very simple. Just display different labels according to the type passed through the interface. The code is as follows:
The above is the detailed content of Detailed explanation of an example of how WeChat applet implements graphic and text display function on headline news details page. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment