Jump to content

Getting the first two characters after $needle in $haystack?


torb

Recommended Posts

Hi there! I have been browsing for quiiite a few hours both here and in the PHP manual looking for a simple way to find some characters in strings.

 

I've tried regex and all sorts of preg_matches and whatnot, but my skills simply aren't there.

 

Anyways, here's my example. Let's say a forum post string reads like this...

Sed fermentum velit vel orci posuere nec ultrices lacus congue. Phasellus non justo non nibh elementum consectetur. Praesent ut magna orci. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

[special]42

Quisque id mi turpis, in fringilla tortor. Vestibulum rutrum adipiscing lacus. Duis auctor cursus consectetur. Quisque id arcu at eros laoreet vulputate. Nam tincidunt nunc id sem sagittis pharetra. Aenean eu sapien ut quam dapibus ultrices.

 

...then I want the result value 42 in a new variable.

So basically, I want the two characters AFTER [special] as a new variable...

 

Any help is greatly appreciated! :)

 

-torb

 

PS: I would be very willing to change it to [special]42[/special] to make it look more like bbCode.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.