Reputation: 25
i want to remove all the text after the last occurring of " . " in a given paragraph.
For example from this paragraph i want to remove all text after last full stop.
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Rich
Length of the paragraph is dynamic only thing to be removed is text after last " . "
Upvotes: 0
Views: 3296
Reputation: 959
For me, the above solutions didn't work out so finally i got some code by myself so it may help to other people.
<?php
$trim_content = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Rich";
$place = strripos($trim_content,".");
$content = substr($trim_content,$place);
echo str_replace($content,".",$trim_content);
?>
Upvotes: 0
Reputation: 31
You can do it with explode.
$summary = explode(".",$summary);
$summary=$summary[1]
here you will get text till the first full stop
Upvotes: -1
Reputation: 1719
Maybe something like this:
new_string = substr(old_string, 0, strchr(old_string, '.'));
strchr
finds the position of the last occurrence of '.' in old_string
. substr
returns a new string consisting of the characters in old_string
between positions 0 and the position found by strchr
.
Upvotes: 0