Laravel Extract Excerpt From Content Using Tinymce
I'm using tinymce as rich text editor and separate excerpt from content via pagebreak button that insert a
<!-- pagebreak --> tag . I'm wondering what is the best way to extract excerpt from database.
I know i can use
preg_math as well as
preg_split , but is it realy best and optimized solution?
wouldn't it be better and faster to save excerpt in a separate column?
This should work, without using any regex functions:
$pagebreak = '<!-- pagebreak -->'; $content = 'I am the excerpt<!-- pagebreak -->I am the rest of the content'; $excerpt = substr($content, 0, strpos($content, $pagebreak)); $restOfTheContent = substr($content, strpos($content, $pagebreak) + strlen($pagebreak)); var_dump($excerpt); // string(16) "I am the excerpt" var_dump($restOfTheContent); // string(28) "I am the rest of the content"
Please note that this is really only designed to work with a single page break. It wouldn't be too difficult to modify it to generate an array of
$pages based off of the string
$content should multiple page breaks be necessary.
- → How to replace *( in a string
- → Regex extract string after the second "." dot character at the end of a string
- → JS Get multiple links in a string
- → Using capture group $1 to access object's key value
- → In Nginx, how to match and entire URL and Query String and redirect to a URL and Query String
- → Reorder lines in a string based on first two numbers inside
- → How to manage URL with or without ? and /
- → Not sure why this Regex is returning true
- → Laravel extract excerpt from content using tinymce
- → Cannot get my multiple regex working for specific case in URL structure
- → laravel5.1 validate number