t0berius's avatar

remove markdown from string

A product description can contain markdown, but for some kind of warehousing the description needs to be loose of markdown.

Using this package to render markdown:

https://github.com/GrahamCampbell/Laravel-Markdown

But for some kind of machine readable description I would need to make sure a string doesn't contain any markdown, any idea how to do so?

0 likes
6 replies
Sinnbeck's avatar

Just convert it to html with that package, and then do this

$text = strip_tags($html);
2 likes
t0berius's avatar

@Sinnbeck That's a way to go, but this will remove f.e. tags but the links will remain, an idea how to remove tags and "links" (ressource links), since the description may contain tags / markdown image include too?

Sinnbeck's avatar

@t0berius I am quite sure that images will just be removed, and links will be turned into whatever is between the tags

<a href="https://laracasts.com/">laracasts</a> //before
laracasts //after
d4storm's avatar

@Sinnbeck Removing MD is not same like strip_tags! Example after strip tags:

“Тежките времена раждат силни хора. Силните хора раждат лесни времена. Лесните времена раждат слаби хора. Слабите хора раждат трудни времена.“ > -- just saying :-)

Please or to participate in this conversation.