Skip to content

Instantly share code, notes, and snippets.

@harini-ua
Created June 20, 2017 08:44
Show Gist options
  • Save harini-ua/97110a9ad1450bed554af1739ea8caf2 to your computer and use it in GitHub Desktop.
Save harini-ua/97110a9ad1450bed554af1739ea8caf2 to your computer and use it in GitHub Desktop.
<?php
/**
* Returns a summary of thep rovided text
* @param [type] $text $text to be summarized
* @param integer $length lenght in chars to keep
* @return [type] summarized text
*/
function summary($text, $length = 200)
{
if (strlen(str_limit(strip_tags($text))) > $length)
{
$post = ' ...'; // append if it's longer than length
}
else
{
$post = '';
}
return str_limit(strip_tags($text), $length) . $post;
}
function safe_html($content)
{
return strip_tags($content, '<br><p><a><li><img><hr><em><strong><i><code><h1><h2><h3><h4><ul><ol>');
}
/**
* returns the value of $name setting as stored in DB // TODO refactor
*/
function setting($name, $default = false)
{
$setting = \App\Setting::where('name', $name)->first();
if ($setting)
{
return $setting->value;
}
return $default;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment