Jump to content

Help with Character extraction


mcmuney

Recommended Posts

I'm trying to pull a certain number of characters after a specific character. For example:

 

$data="x=1234567"

 

I'd like to pull 7 characters after "x=". So the result whould be "1234567".

 

I couldn't use strpos because the 7 characters will NOT always begin from the 3rd character. For example, it could be "x=" or "tyx=" or "1x=", etc. I only want what's after "x=".

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/273365-help-with-character-extraction/
Share on other sites

What's wrong with just substr (), I mean if you know you always want 7 characters?

php > $data="x=1234567";
php > echo substr ($data, -7);
1234567

 

Otherwise, you can use strpos () to find the position of the equals sign, and send that value to substr ().

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.