HtmlCropper implements LoggerAwareInterface uses LoggerAwareTrait
Table of Contents
Interfaces
- LoggerAwareInterface
Constants
- TAGS = 'a|abbr|address|area|article|aside|audio|b|bdi|bdo|blockquote|body|br|button|caption|cite|code|col|colgroup|data|datalist|dd|del|dfn|div|dl|dt|em|embed|fieldset|figcaption|figure|font|footer|form|h1|h2|h3|h4|h5|h6|header|hr|i|iframe|img|input|ins|kbd|keygen|label|legend|li|link|main|map|mark|meter|nav|object|ol|optgroup|option|output|p|param|pre|progress|q|rb|rp|rt|rtc|ruby|s|samp|section|select|small|source|span|strong|sub|sup|table|tbody|td|textarea|tfoot|th|thead|time|tr|track|u|ul|ut|var|video|wbr'
- TAGS_REG_EXP = ' ( (?: <!--.*?--> # a comment | <canvas[^>]*>.*?</canvas> # a canvas tag | <script[^>]*>.*?</script> # a script tag | <noscript[^>]*>.*?</noscript> # a noscript tag | <template[^>]*>.*?</template> # a template tag ) | </?(?:%s)+ # opening tag (\'<tag\') or closing tag (\'</tag\') (?: (?: (?: \s+\w[\w-]* # EITHER spaces, followed by attribute names (?: \s*=?\s* # equals (?> ".*?" # attribute values in double-quotes | \'.*?\' # attribute values in single-quotes | [^\'">\s]+ # plain attribute values ) )? ) | # OR a single dash (for TYPO3 link tag) (?: \s+- ) )+\s* | # OR only spaces \s* ) /?> # closing the tag with \'>\' or \'/>\' )'
Methods
- crop() : string
- Implements "cropHTML" which is a modified "substr" function allowing to limit a string length to a certain number of chars (from either start or end of string) and having a pre/postfix applied if the string really was cropped.
- closeCroppedTags() : array<string|int, mixed>
- cropSectionToNextSpace() : string
- getCropPosition() : int
- isTextSection() : bool
- splitContentIntoSections() : array<string|int, mixed>
- Split $content into an array(even items in the array are outside the tags, odd numbers are tag-blocks).
Constants
TAGS
protected
mixed
TAGS
= 'a|abbr|address|area|article|aside|audio|b|bdi|bdo|blockquote|body|br|button|caption|cite|code|col|colgroup|data|datalist|dd|del|dfn|div|dl|dt|em|embed|fieldset|figcaption|figure|font|footer|form|h1|h2|h3|h4|h5|h6|header|hr|i|iframe|img|input|ins|kbd|keygen|label|legend|li|link|main|map|mark|meter|nav|object|ol|optgroup|option|output|p|param|pre|progress|q|rb|rp|rt|rtc|ruby|s|samp|section|select|small|source|span|strong|sub|sup|table|tbody|td|textarea|tfoot|th|thead|time|tr|track|u|ul|ut|var|video|wbr'
TAGS_REG_EXP
protected
mixed
TAGS_REG_EXP
= '
(
(?:
<!--.*?--> # a comment
|
<canvas[^>]*>.*?</canvas> # a canvas tag
|
<script[^>]*>.*?</script> # a script tag
|
<noscript[^>]*>.*?</noscript> # a noscript tag
|
<template[^>]*>.*?</template> # a template tag
)
|
</?(?:%s)+ # opening tag (\'<tag\') or closing tag (\'</tag\')
(?:
(?:
(?:
\s+\w[\w-]* # EITHER spaces, followed by attribute names
(?:
\s*=?\s* # equals
(?>
".*?" # attribute values in double-quotes
|
\'.*?\' # attribute values in single-quotes
|
[^\'">\s]+ # plain attribute values
)
)?
)
| # OR a single dash (for TYPO3 link tag)
(?:
\s+-
)
)+\s*
| # OR only spaces
\s*
)
/?> # closing the tag with \'>\' or \'/>\'
)'
Methods
crop()
Implements "cropHTML" which is a modified "substr" function allowing to limit a string length to a certain number of chars (from either start or end of string) and having a pre/postfix applied if the string really was cropped.
public
crop(string $content, int $numberOfChars, string $replacementForEllipsis, bool $cropToSpace) : string
Parameters
- $content : string
-
The string to perform the operation on
- $numberOfChars : int
-
Max number of chars of the string. Negative value means cropping from end of string.
- $replacementForEllipsis : string
-
The pre/postfix string to apply if cropping occurs.
- $cropToSpace : bool
-
If true then crop will be applied at nearest space.
Return values
string —The processed input value.
closeCroppedTags()
protected
closeCroppedTags(array<string|int, mixed> $sections, int|null $croppedOffset, int $numberOfChars, string $replacementForEllipsis) : array<string|int, mixed>
Parameters
- $sections : array<string|int, mixed>
- $croppedOffset : int|null
- $numberOfChars : int
- $replacementForEllipsis : string
Return values
array<string|int, mixed>cropSectionToNextSpace()
protected
cropSectionToNextSpace(string $contentOfCurrentSection, array<string|int, mixed> $processedTextSectionsForCropping, bool $cropToSpace, bool $cropFromRight) : string
Parameters
- $contentOfCurrentSection : string
- $processedTextSectionsForCropping : array<string|int, mixed>
- $cropToSpace : bool
- $cropFromRight : bool
Return values
stringgetCropPosition()
protected
getCropPosition(string $contentOfCurrentSection, int $numberOfChars, int $strLengthOfAllPrevTextSections, bool $cropFromRight) : int
Parameters
- $contentOfCurrentSection : string
- $numberOfChars : int
- $strLengthOfAllPrevTextSections : int
- $cropFromRight : bool
Return values
intisTextSection()
protected
isTextSection(int $offset) : bool
Parameters
- $offset : int
Return values
boolsplitContentIntoSections()
Split $content into an array(even items in the array are outside the tags, odd numbers are tag-blocks).
protected
splitContentIntoSections(string $content, bool $cropFromRight) : array<string|int, mixed>
Parameters
- $content : string
- $cropFromRight : bool