Created
December 31, 2019 01:58
-
-
Save robertdrakedennis/389d86f42c59b2beb735ff0b578f78d0 to your computer and use it in GitHub Desktop.
Super primitive tiptap json parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Strips the json from a tiptap body. | |
* | |
* @param array $body | |
* @return string | |
*/ | |
function strip_json_body(array $body): string | |
{ | |
$string = ''; | |
foreach ($body['content'] as $content) { | |
if (\Illuminate\Support\Arr::has($content, 'content')) { | |
foreach ($content['content'] as $data) { | |
if (\Illuminate\Support\Arr::has($data, 'text')) { | |
$string .= $data['text'] . ' '; | |
} | |
} | |
} else { | |
$string .= ' '; | |
} | |
} | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is pretty poor but works for now tbh