Skip to content

Instantly share code, notes, and snippets.

@robertdrakedennis
Created December 31, 2019 01:58
Show Gist options
  • Select an option

  • Save robertdrakedennis/389d86f42c59b2beb735ff0b578f78d0 to your computer and use it in GitHub Desktop.

Select an option

Save robertdrakedennis/389d86f42c59b2beb735ff0b578f78d0 to your computer and use it in GitHub Desktop.
Super primitive tiptap json parser
<?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;
}
@robertdrakedennis
Copy link
Author

this is pretty poor but works for now tbh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment