1.

Solve : help with php string please.?

Answer»

Hi,
I have a string which contains lots words with SPACES. I WANT to read a part of the string identified between two words in the STRINGS. Is there any drupal function to do that or any function in php? I know in php SUBSTR() does something similar, but it takes the int as the starting reference, but I want the starting reference to be a string.
Any help will be appreciated.

thanks,
jet ved.
I'm not a PHP user, but substrings are pretty much the same in any language.

Quote

know in php substr() does something similar, but it takes the int as the starting reference, but I want the starting reference to be a string.

Find the substring (word) to be used as the starting reference. Add the length of the word to the integer location of the word. Add 1 for the space. The result should be the integer starting point of the identified string.

On the back end, find the starting location of the word used as the ending reference. Subtract 1 for the space. The result should be the ending point of the identified string.

Good luck. Can you post the strings you have?Thanks SIDEWINDER for the reply.
sorry for being out for some time.
Actually the reference word keeps changing. But I can identify it easily using the '_xx' where xx is any two chars.
For example, I want to read the below string. So I need to store the sub string from '_ab' to '_ti' into one variable and from '_ti' to '_li' into another variable and so on...

example string: "_ab One-year-ahead forecasts _ti national institutes of GDP growth _li European _ab Secondary information _ti exponential forecasting _ab"...

This is just one example of the kind of strings I will be using.
Thanks kpac for help in advance.


Discussion

No Comment Found