I'm creating a Blog that uses a Faker Factory to generate Demo Data. I have a Post Model which is generated that has a body field which contains randomly generated HTML as well as a text field which is created by stripping the tags from the body and limiting the data received to 512 characters. str_limit works fine it is just that I need to cut the text off on a word while keeping it in the 512 limit.
This is my factory:
<?php
use Faker\Generator as Faker;
$factory->define(Provar\Forum\Post::class, function (Faker $faker) {
$randomHTML = Purifier::clean($faker->randomHtml(2,3));
$trimedHTML = strip_tags($randomHTML);
return [
'body' => $randomHTML,
'text' => str_limit($trimedHTML, 509, '...')
];
});
Any help is appreciated. <3