Skip to content

Instantly share code, notes, and snippets.

@AlexGx
Created March 17, 2016 22:01
Show Gist options
  • Save AlexGx/ba97ba86a566eb9627c7 to your computer and use it in GitHub Desktop.
Save AlexGx/ba97ba86a566eb9627c7 to your computer and use it in GitHub Desktop.
<?php
/**
* @param bool $short
* @return string
*/
public function getContent($short = true)
{
$body = $this->site_content;
// TODO: remove shortend
if (preg_match("~(<p[^>]*>\s*)?\{\{shortend\}\}(\s*<\/p>)?~i", $body, $match, PREG_OFFSET_CAPTURE)) {
if ($short) {
$body = substr($body, 0, $match[0][1]);
} else {
$full_len = strlen($match[0][0]);
$start = $match[0][1] + $full_len;
$body = substr($body, $start, strlen($body) - $start - 1);
}
}
return $body;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment