[英]How can I call npm module from PHP class
I found a javascript plugin to convert HTML to markdown here https://github.com/domchristie/to-markdown . 我在这里https://github.com/domchristie/to-markdown找到了一个可将HTML转换为markdown的JavaScript插件。
I'm using Laravel 5. Let's say a user post an HTML string and I take the request from my PHP class. 我正在使用Laravel5。假设某个用户发布了HTML字符串,然后从我的PHP类中获取了请求。 Here's my controller: 这是我的控制器:
<?php
class TheController extends Controller
{
...
public function index()
{
$html_text = Request::input('html_text');
// Convert $html_text to $markdown
}
}
?>
If I were in a javascript file I could've called the function like this: 如果我在一个javascript文件中,我可以这样调用函数:
var toMarkdown = require('to-markdown');
toMarkdown('<h1>Hello world!</h1>');
How do I convert $html_text
to $markdown
without converting it to a text file and read it, if possible 如何将$html_text
转换$html_text
$markdown
而不将其转换为文本文件并读取(如果可能)
You shouldn't use a npm package for that, there are plenty php packages to do this. 您不应该为此使用npm软件包,有很多php软件包可以做到这一点。 You can find a lot of packages compatible with Laravel on packalyst . 你可以找到很多与Laravel兼容包packalyst 。
For example: http://packalyst.com/packages/package/alfredo-ramos/parsedown-extra-laravel 例如: http : //packalyst.com/packages/package/alfredo-ramos/parsedown-extra-laravel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.