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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.