Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert php Rich text to html

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to convert php rich text to html". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The method of converting php rich text to html: 1. Open the corresponding code file and modify the image path; 2. Convert it to html using phpword, such as "$phpWord = new\ PhpOffice\ PhpWord\ PhpWord..."

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How to transfer php rich text to html?

PHP rich text to html, word, pdf file download

I use layui here because it is light.

As for how rich text uses documentation, it's very simple to talk about it if you have a problem: http://www.layui.com/doc/modules/layedit.html.

Then after the rich text data access, take out the content you want:

1. Transfer to html

$html = "here is what you want!"

The first line is because the picture path is wrong and cannot be displayed, so the picture path has been replaced correctly.

Or you can use phpword to convert it to html. For example, the demo of phpword above, please refer to

Phpword (composer): composer require phpoffice/phpword

AddSection (); / / add text elements by default. The style of the font has section $- > addText ("'learn from yesterday, live in today, look forward to tomorrow.' the most important thing is not to stop asking questions.'" (Einstein)'); / * Note: there are three ways to customize the font style of added Text elements: *-inline; *-use the specified font style (implicitly create a new font style object); *-use a font style object that is explicitly created. * / / 'add text elements with font custom inline... $section-> addText (' 'great achievements are usually due to great sacrifices''. And it is never the result of selfishness.' .' (Napoleon Hill)', array ('name' = > 'Tahoma', 'size' = > 10)); / / add text elements using the specified font style custom font. $fontStyleName = 'oneUserDefinedStyle'; $phpWord-> addFontStyle ($fontStyleName, array ('name' = > 'Tahoma', 'size' = > 10, 'color' = > '1B2232', 'bold' = > true) $section-> "the greatest achievement is not to never fall, 'but in rising again you fall." '.' (Vince Lombardi)', $fontStyleName); / / add text elements of custom fonts using explicitly created font style objects... $fontStyle = new\ PhpOffice\ PhpWord\ Style\ Font (); $fontStyle-> setBold (true); $fontStyle-> setName ('Tahoma'); $fontStyle-> setSize (13); $myTextElement = $section-> addText ('"I believe you can re-halve with you." (Theodore Roosevelt)'); $myTextElement-> setFontStyle ($fontStyle); / / Save the document as an OOXML file... $objWriter =\ PhpOffice\ PhpWord\ IOFactory:: createWriter ($phpWord, 'Word2007'); $objWriter-> save ('helloWorld.docx'); / / Save the document as an ODF file... $objWriter =\ PhpOffice\ PhpWord\ IOFactory:: createWriter ($phpWord, 'ODText'); $objWriter-> save ('helloWorld.odt') / / Save the document as a HTML file... $objWriter =\ PhpOffice\ PhpWord\ IOFactory:: createWriter ($phpWord, 'HTML'); $objWriter-> save ('helloWorld.html'); / * Note: we skip RTF because it is not based on XML and requires a different example. * / / * Note: we skipped PDF because the "HTML-to-PDF" method is used to create PDF documents. * /

2. Transfer to word

(1) use PHP built-in file_put_contents (), I try to save as word, the original html tags will all exist, unless you need rich text or html source code, it doesn't make any sense.

(2) use cache: to display pictures downloaded locally, you can only use network address (IP or domain name).

$wors = str_replace ("/ uploads/layui/", "http://172.16.3.125/notes/public/uploads/layui/",$html);$this->start();$newname = 'pppp';$wordname =' files/word/'.$newname." .doc "; / / generate file path echo $wors;$this- > save ($wordname); ob_flush (); / / refresh cache flush () before each execution; function start () {ob_start () Echo 'Print';} function save ($path) {echo "; $data = ob_get_contents (); ob_end_clean (); $this- > wirtefile ($path,$data);} function wirtefile ($fn,$data) {$fp=fopen ($fn," wb "); fwrite ($fp,$data); fclose ($fp);}

(3) phpword can also be converted to word. For example, the demo of phpword above can be referenced, but if the image is downloaded locally, you can only use the network address (IP or domain name).

(4) there are examples on the Internet that convert html to mht and then transfer the image text word, which is thought to be too long, so take a look at ε ≡ (">" where ('id',12)-> find (); $title =''. $html ['notename']. ''; $content = $html ['content']; $mpdf = new Mpdf (); $mpdf- > autoScriptToLang = true; $mpdf- > autoLangToFont = true; $header=' this is my header'; $mpdf- > SetHTMLHeader ($header) / / header / / $mpdf-> WriteHTML ('Hello world! '); $mpdf- > WriteHTML ($title.$content); $mpdf- > Output (); / / $mpdf- > Output (' files/word/one.pdf','D'); / / Save as a file} "how to transfer php Rich text to html" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report