Is it possible to use words as starting and ending points of excerpt parameters?

I want to find a way for excerpt function to display exactly what i want inside a single post. the excerpt itself has st

I want to find a way for excerpt function to display exactly what i want inside a single post. the excerpt itself has starting and ending point as parameters to go and fetch the data. but what if i want to use words instead of them.

default:

$theExcerpt = get_the_content();
echo substr($theExcerpt,0,200);

I want this:

$theExcerpt = get_the_content();
echo substr($theExcerpt,'begining of paragraph', 'end of paragraph');

I want to find a way for excerpt function to display exactly what i want inside a single post. the excerpt itself has starting and ending point as parameters to go and fetch the data. but what if i want to use words instead of them.

default:

$theExcerpt = get_the_content();
echo substr($theExcerpt,0,200);

I want this:

$theExcerpt = get_the_content();
echo substr($theExcerpt,'begining of paragraph', 'end of paragraph');

Share Improve this question edited Jan 10, 2020 at 16:22 Ashur asked Jan 10, 2020 at 11:23 AshurAshur 233 silver badges8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I think this is more a PHP than a WP question. Try using a regular expression with preg_match:

$theExcerpt = get_the_content();
$returnValue = preg_match('/(string01)(.*)(string02)/', $theExcerpt); 
echo $returnValue[0];

You have to replace string01 and string02 with your 'begining of paragraph' and 'end of paragraph'. There might be a more elegant way of using preg_match, but I think this will do the trick.

Don't forget to escape the output

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744844770a4596765.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信