How does php generate an word document from a rich text string?

problem description

I now have a rich text string,
such as $str= "

< span style=" color: rgb (255,0,0); ">

< hr/ >

< span style=" color: rgb (255,0,0); "> qq < span style=" color: rgb (0,176240); "> Q Baidu URL

(base64 coding of very long pictures) > < span style= "color: rgb (255,0,0);" > < span style= "color: rgb (0176240);" > < br/ >

;
I omitted a lot of picture base64 coding.

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

I found relevant methods on the Internet, such as this:
first create a class:
class Exportword
{

function start()
{
    ob_start();
    echo "<html xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:w="urn:schemas-microsoft-com:office:word"
    xmlns="http://www.w3.org/TR/REC-html40">";
}
function save($path)
{

    echo "</html>";
    $data = ob_get_contents();
    ob_end_clean();

    $this->wirtefile($path, $data);
}

function wirtefile($fn, $data)
{
    $fp = fopen($fn, "wb");
    fwrite($fp, $data);
    fclose($fp);
}
The code that

}
then implements is as follows:
$exportWord = new Exportword ();
$exportWord- > start ();
$fileName ="my study Notes". Date ("Y-m-d Hpuri"). ".docx";
$wordPath = $save_path. $fileName;
echo $str;
$exportWord- > save ($wordPath);
ob_flush (); / / refresh the cache
flush ();

before each execution

what result do you expect? What is the error message actually seen?

after this execution, the file is generated, but there are two problems.
question 1. The image of the generated file can not be displayed (not displayed properly), and other rich text information can be written into the word document normally.
question 2. When the generated file is opened using office, there will be an error and cannot be opened, but it can be opened using wps. Why?

ask God to help me solve the above two problems, or not to use the method above, whether there are other ways to convert rich text to word, and use office to open it normally, and the content will display normally.

Oct.28,2021

suggest you find a plug-in to do it. Doc and docx formats are packaged in zip, do not believe you use word to create a new file, and then drag to any unzipped software, you can see the structure. You can't open it with office because the format you generate is illegal at all, and wps can be opened because Jinshan has strong compatibility and all kinds of structures, but it doesn't mean your file is OK.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35dcc-2b32f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35dcc-2b32f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?