Forum Moderators: coopster

Message Too Old, No Replies

Reversing strrchr

         

internetheaven

4:56 pm on Mar 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've found the code that will find a character (in this example a full-stop) and then show everything after that point:

$a[array] = strrchr($a[array], ".");

I want it to do the reverse, I want it to find the LAST full-stop in a string and then return everything BEFORE it. I've tried:

$a[array] = reverse_strrchr($a[array], ".");

but I guess it wasn't going to be that easy! :)

ergophobe

5:05 pm on Mar 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Assuming you want the string up to the first full stop, I cna think of a couple of ways.

These should both return the string up to the full stop.

$a = "A string with a full stop. And then another phrase or two.";

$a = substr($a, 0, strpos($a, "."));

-- or --

$x = explode($a, '.');
$a = $x[0];

internetheaven

6:13 pm on Mar 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming you want the string up to the first full stop

As stated I want it to go to the LAST full stop. There is around 2-4 sentences then a bunch of nonsense characters afterward:

e.g. "This example sentence is ther first sentence. This example sentence is the second one, though very similar to the first. And this sentence is the third. Then thingssss just goabit wierd 2938? from here 90ju"

I want it to show only the stuff before the last full stop. Thanks.

internetheaven

6:31 pm on Mar 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's okay, I found it = strrpos

Thanks for pointing me in the right direction! :)

ergophobe

8:13 pm on Mar 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Stupid me! I could have sworn you asked about the LAST full stop and then when I went back and looked at the post before replying, I couldn't find mention of it despite being in ALL CAPS.

Sorry about that, but glad you got it sorted. Actually, I would prefer to point someone in the right direction and then have them figure it out on their own anyway, so can I just pretend that was intentional?

Cheers!